Use of Shift command | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Use of Shift command

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 11-03-2011
aks_1902 aks_1902 is offline
Registered User
 
Join Date: May 2011
Last Activity: 3 November 2011, 2:12 AM EDT
Posts: 35
Thanks: 21
Thanked 0 Times in 0 Posts
Use of Shift command

Hello Expert

Can any one please explain what is the use of shift command in general terms:


Code:
set -- $(ls -t)
	shift
	rm -Rf $*

what is the use of shift command over here.

Thanks a lot for your help
Sponsored Links
    #2  
Old 11-03-2011
ahamed101's Avatar
ahamed101 ahamed101 is offline Forum Advisor  
root is god!!!
 
Join Date: Sep 2008
Last Activity: 15 May 2014, 2:54 PM EDT
Location: San Jose, CA
Posts: 1,906
Thanks: 54
Thanked 485 Times in 478 Posts
Try this to get the concept...

Code:
[root@bt] $ cat run
#!/bin/bash

set -- "1" "2" "3" "4" "5"
echo $*
shift
echo $*
shift
echo $*
shift
echo $*

Output

Code:
[root@bt] $ ./run
1 2 3 4 5
2 3 4 5
3 4 5
4 5

It will shift the arguments from right to left
Lets say, you have 3 arguments i.e. $1=a, $2=b, $3=c
Now you "shift" and try priting $1, it will print "b" and $2 will be "c" and there will no $3

HTH
--ahamed
The Following User Says Thank You to ahamed101 For This Useful Post:
aks_1902 (11-03-2011)
Sponsored Links
    #3  
Old 11-03-2011
aks_1902 aks_1902 is offline
Registered User
 
Join Date: May 2011
Last Activity: 3 November 2011, 2:12 AM EDT
Posts: 35
Thanks: 21
Thanked 0 Times in 0 Posts
Awesome!!!! Thanks a lot
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
AIX command to shift up bombcan Shell Programming and Scripting 4 08-19-2009 03:04 PM
Regarding the shift command??? shrao Shell Programming and Scripting 2 03-31-2007 03:39 AM
shift command Nisha Shell Programming and Scripting 6 07-19-2002 05:54 AM
shift command AkumaTay UNIX for Dummies Questions & Answers 1 05-20-2002 08:26 AM



All times are GMT -4. The time now is 10:10 PM.