I had a need to pass command line arguments to a bash script. Here’s an easy solution that I came across that can interpret both short- and long- command-line arguments.
#!/bin/bashwhile [[ "$#" -gt 0 ]]; do
case $1 in
-p|--profile) PROFILE="$2"; shift;;
-r|--region) REGION="$2"; shift;;
*) echo "Unknown parameter passed: $1"; exit 1;;
ecas
shift
doneecho "PROFILE IS ${PROFILE}"
echo "REGION IS ${REGION}"
Let’s test it
bash test.sh -p user -r US