1827802 Members
2291 Online
109969 Solutions
New Discussion

SHIFT

 
SOLVED
Go to solution
malay boy
Trusted Contributor

SHIFT

NAME=$1
shift

Guru,
Any idea what this shift is doing.

regards
mB
There are three person in my team-Me ,myself and I.
5 REPLIES 5
Hein van den Heuvel
Honored Contributor
Solution

Re: SHIFT

May we assume this is in some shell environment, not perl or awk or some such?

Try 'man ksh' and search for shift '/shift':
Here is what I get:
% shift [n] The positional parameters from $n+1 ... are renamed
$1 ...; default n is 1. The parameter n can be any
arithmetic expression that evaluates to a non-negative
number less than or equal to $#.


So what was $2 now becomes $1
Seems usefull in a parameter processing loop.

hth,
Hein.

Abdul Rahiman
Esteemed Contributor

Re: SHIFT

If this "Shift" is indeed about the shell shift, following shell script tutorial might help.. (Anyways, would be better than me explaining it..:-)

http://unix.about.com/library/course/blshscript-l5b.htm

regds,
Abdul.
No unix, no fun
T G Manikandan
Honored Contributor

Re: SHIFT

shift

moves the values stored in command line arguments to left one position

For ex,

assume

$1=mala $2 boy
alter executing the shift statement

$1=boy $2=
Michael Tully
Honored Contributor

Re: SHIFT

Hi mB,

The shell man pages hae the answer, although TG's answer is a good example.

% shift [n]
Rename the positional parameters from n+1 ... to 1 .... The default value of n is 1. n can be any arithmetic expression that evaluates to a nonnegative number less than or equal to $#.

source: sh-posix
Anyone for a Mutiny ?
R. Allan Hicks
Trusted Contributor

Re: SHIFT

Just for grins try

create shift_it containing


#!/bin/ksh
#
echo $1
shift
echo $1

chmod 755 shift_it

shift_it hello world

verify the output

hello
world

"Only he who attempts the absurd is capable of achieving the impossible