i am executing shell script called ./myscript.sh with 2 options like below
./myscript.sh -d /root/ -n "dhoni" "kohli"
first option is -d and value is /root/
second option is -n and values are dhoni and kohli for this in the current example
But each time while executing this script number of names passed to this script for -names option may vary
the code i have written for this is
EMPNAMES=("$@")
while getopts "d:n:" arg; do
case "$arg" in
d) PATH="$OPTARG"
;;
n) EMPNAMES="$OPTARG"
;;
for arg in "${EMPNAMES[@]}"; do
echo "$arg"
done
it should print
dhoni
kohli
But it is printing
dhoni
/root/
-names
dhoni
kohli