I have the following switch case in the script:
while [ $# -gt 0 ] ; do
case "$1" in
-f|--file)
shift
f=$1
;;
-s|--string)
s=$2
shift
;;
-c|--client)
c=$3
shift
;;
-h|-help)
_usage
;;
-*)
_usage
;;
esac
shift
done
When I run this though, I can never get the -c passed with the String i pass it. It always is blank. I am not sure why this is the case since the first two vars are passed (i.e -f and -s). Can someone advise why this might be occurring?
Here is what I do, expecting that ybdemo would be passed to -c:
./find_prod_andfix.sh -f /etc/bar/active_clients -s foo -c "ybdemo"
Mon Aug 27 14:51:22 EDT 2018 find_prod_andfix.sh 11351 INFO: /etc/bar/active_clients
Mon Aug 27 14:51:22 EDT 2018 find_prod_andfix.sh 11351 INFO: foo
Mon Aug 27 14:51:22 EDT 2018 find_prod_andfix.sh 11351 INFO:
Mon Aug 27 14:51:22 EDT 2018 find_prod_andfix.sh 11351 INFO: Checking -- Client ID:
This is where in the script I echo out the info above:
if [[ -z $c ]]; then
_info ${f}
_info ${s}
_info ${c}
_info "Checking ${line} -- Client ID: ${CLIENT_ID}"
fi
Any suggestions would be very helpful.
set -xenabled and I believe you will see that you areshifting things and then still looking at$3when you should be looking at$1or$2depending on where youshift(you are inconsistent about this).