0

I want for example write all arguments using for loop, when I write:

for (( i=1; $i <= $#; i++ )) ; do
    echo "${$i}"
done

or

echo "$$i"

it doesn't work. I can't also do loop:

for arg in "$@"

Because I want to have acces to next argument, if current is for example "-n". (My line of arguments will be e.g -n 10 -k 50 -s 4)

Niko13
  • 9
  • 3
    Use indirection `echo "${!i}"`.http://www.tldp.org/LDP/abs/html/ivr.html. Also this is 100% a duplicate but i can't be bothered finding it if anyone else wants to. – 123 May 25 '16 at 08:45

1 Answers1

0

Why don't you use getopts ?

while getopts ':n:k:s:' opt
do
case "$opt" in 
n) echo "option n with $OPTRARG"
   ;;
k) echo "option k with $OPTRARG"
   ;;
s) echo "option s with $OPTRARG"
   ;;
*) echo "Bad usage"
esac
done
Мона_Сах
  • 322
  • 3
  • 12