The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Password cannot be circular shift of logonid sag71155 HP-UX 2 05-09-2008 02:04 AM
Regarding the shift command??? shrao Shell Programming and Scripting 2 03-31-2007 12:39 AM
Bit shift operator naan High Level Programming 5 09-07-2006 11:13 PM
shift command Nisha Shell Programming and Scripting 6 07-19-2002 02:54 AM
xterm SHIFT crazy oneivan UNIX for Dummies Questions & Answers 2 06-05-2002 01:29 AM

Closed Thread
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-19-2002
Registered User
 

Join Date: Jul 2001
Location: Malaysia
Posts: 21
Stumble this Post!
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?
Forum Sponsor
  #2 (permalink)  
Old 05-20-2002
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,430
Stumble this Post!
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
Google The UNIX and Linux Forums
Closed Thread

Thread Tools
Display Modes




All times are GMT -7. The time now is 01:02 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0