shift command

There is an error when i am trying to use the shift command in this way:

($1 = -d, $2 = 123, $3 = -c etc etc)

for $arg in $@
do
case $arg in
"-d") shift; (so that the $2 will become the $arg now)
(and while it loop the 2nd time,)
($arg will become $3 which is -c)
;;
done

Anyone know how can i do that? :slight_smile:

Your for statement is already stepping though the args. Don't use "shift" at all in your loop and it should work.

In your previous thread, I showed you:

for parm ; do
echo $parm is a parameter
done

This will work exactly the same as:
for parm in "$@" ; do
echo $parm is a parameter
done

But you left the quotes off with your loop. If you have a parameter list like:
./script one 222 "333 3333" 4444
that third parameter will be split in two pieces with your loop. You will also have trouble with a null parameter:
./script one 222 "" 4444

To use shift, one way is
while [ $# -gt 0 ] ; do
echo $1 is a parm
shift
done