shift and args

   3489   4   1
User Avatar
Member
176 posts
Joined: July 2005
Offline
the help doesnt have much on the shift command….it explains the use, but not really how to use it.

anyone know the syntax?
User Avatar
Member
321 posts
Joined: July 2005
Offline
lynch_ppl
the help doesnt have much on the shift command….it explains the use, but not really how to use it.

anyone know the syntax?

Simple:

shift

that's it!

all it does is pop off the left-most arg on the script's argument list, and reassign $arg1, $arg2, and so on.

– Antoine
Antoine Durr
Floq FX
antoine@floqfx.com
_________________
User Avatar
Member
166 posts
Joined: Feb. 2006
Offline
In case…

the following script executed as source myShiftScript.cmd A B C D


for i = 1 to 4
shift
echo $arg0
end


will give the following
A
B
C
D
to clear the help example.
Time to get out of this messy world.
User Avatar
Member
176 posts
Joined: July 2005
Offline
thanks….
i guess the syntax for that one is as simple as Antoine said….shift
User Avatar
Member
321 posts
Joined: July 2005
Offline
lynch_ppl
thanks….
i guess the syntax for that one is as simple as Antoine said….shift

Yep. What's missing from the implementation is the “shifting” of an arbitrary variable name, e.g.


shift foobar


which would let you have word lists that you could reduce one arg at a time. For that matter, it would be cleaner to match Perl's operators, shift, unshift, push, pop, and splice. But oh well…

– Antoine
Antoine Durr
Floq FX
antoine@floqfx.com
_________________
  • Quick Links