bash - getops 1 option to receive 2 arguments -
i've searched around found out getops receives 0 or 1 argument only, need make work,
i need make script run this: ./script.sh -a string integer
what write string , integer text file.
i tried code:
while getopts a:d opt case "$opt" in a) na1=$optarg eval "na2=${optind}" shift 2 ;; d) ./views.sh;; esac done if [ $isdef -eq 0 ] echo "$na1;$na2" >>pbdb.txt fi
i can write string part text file integer keeps resulting "3".
sample: ./script.sh -a power 0000
result inside textfile: power;3
any suggestions?
just started learning bash scripting
assuming bash tag accurate (you're not using /bin/sh), change
eval "na2=${optind}"
to use "indirect variable"
na2=${!optind}
with eval, you'd need eval na2=\$$optind
that's uglier
Comments
Post a Comment