can someone explain shift command in script?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers can someone explain shift command in script?
# 1  
Old 11-22-2011
can someone explain shift command in script?

think using shift would help me finish my script but cant get it work without your help. would appreciate if you give me a example with shift & counter in the same script so I can later work on that to my one.

Thanks and Good Luck!
# 2  
Old 11-22-2011
Hi

from 'man bash':

Code:
       shift [n]
              The  positional parameters from n+1 ... are renamed to $1 ....  Parameters represented by the numbers $# down to $#-n+1 are unset.  n must be a non-
              negative number less than or equal to $#.  If n is 0, no parameters are changed.  If n is not given, it is assumed to be 1.  If n  is  greater  than
              $#, the positional parameters are not changed.  The return status is greater than zero if n is greater than $# or less than zero; otherwise 0.

so the effect is basically to switch to the (n+1)th command parameter.

Anyway, what are you actually trying to accomplish?

fra
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shift command help

#!/bin/bash hostname=$1; shift for hostname in $1 do ping $hostname done I want to run the above script as hostname.sh yahoo.com google.com cnn.com. I want to shift each hostname to $1. How can do that with above code as currently it's not shifting. (5 Replies)
Discussion started by: scj2012
5 Replies

2. Shell Programming and Scripting

Use of Shift command

Hello Expert Can any one please explain what is the use of shift command in general terms: set -- $(ls -t) shift rm -Rf $* what is the use of shift command over here. Thanks a lot for your help (2 Replies)
Discussion started by: aks_1902
2 Replies

3. Shell Programming and Scripting

shell script: cannot shift error?

This is an assignment where we were supposed to create a script to get an orginal string and replace it with another. However when I run my script (change-lines), it says ./change-lines: cannot shift I do not where the problem is. help! #!/bin/sh # a shell function to print and error... (4 Replies)
Discussion started by: alis
4 Replies

4. Shell Programming and Scripting

Please Explain me this command

find . -type f -ctime +3 -exec mv {} /somedirectory/ \; in particular "-ctime v/s -mtime" and "difference between +3 and -3" (5 Replies)
Discussion started by: Rambo
5 Replies

5. Shell Programming and Scripting

Shift report script

hey guys, so i'm running into a wall here with my script. i simply can't figure out a way to get it to work. so, maybe you guys can help me. i'm trying to created a report of server alerts based on the time worked. what i have so far is curling nagios pages, removing all the extra html tags and... (4 Replies)
Discussion started by: terrell
4 Replies

6. Shell Programming and Scripting

script assistance with shift J

Hey all, I need some assistance. I'm writing a script to eject tapes from a tape library, but the library is not a queued system and can only eject 15 tapes at a time. I added paste -d : -s so that it goes through full_tapes and puts each media_id on one line separated by the :. Now I'm... (2 Replies)
Discussion started by: em23
2 Replies

7. Shell Programming and Scripting

AIX command to shift up

I would need the awk command or a better way to get my file that looks like 1234 5678 8912 3456 7890 to look like 1234,5678,8912,3456,7890 Thanks in advance (4 Replies)
Discussion started by: bombcan
4 Replies

8. Shell Programming and Scripting

Regarding the shift command???

I am running a program where in I have this command which is giving error the shift: number is not correct. can you please tell me how shift actually works? the line which is giving error is- set $PARAM; shift; shift; shift; shift; shift; shift; shift; shift Is it related somewhere to... (2 Replies)
Discussion started by: shrao
2 Replies

9. Shell Programming and Scripting

shift command

Hi Folks, In shell scripting the maximum no. of command line parameters becomes 9(Am i right). If we want to get more than 9 parameters we use the shift command. Even here there are two possibilities. 1. Without the use of variables - The arguments are lost and the lost no. is equal to the... (6 Replies)
Discussion started by: Nisha
6 Replies

10. UNIX for Dummies Questions & Answers

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,) ... (1 Reply)
Discussion started by: AkumaTay
1 Replies
Login or Register to Ask a Question