The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


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

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
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
shift command AkumaTay UNIX for Dummies Questions & Answers 1 05-20-2002 05:26 AM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-29-2007
Registered User
 

Join Date: Mar 2007
Posts: 4
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 these parameters which is set before this line
PARAM=$*

case "$1" in
"-h"|"-H")
give_help
exit -1
;;
"-p"|"-P")
give_params
exit -1
;;
esac

eval REQID=`echo $PARAM | awk ' { split($2, var, "=")
printf("%s", var[2]) }'`
eval LOGIN=`echo $PARAM | awk ' { split($3, var, "=")
printf("%s", var[2]) }'`
eval USRID=`echo $PARAM | awk ' { split($4, var, "=")
printf("%s",var[2]) }'`
eval USRNM=`echo $PARAM | awk ' { split($5, var, "=")
printf("%s", var[2]) }'`
eval PRINT=`echo $PARAM | awk ' { split($6, var, "=")
printf("%s", var[2]) }'`
eval SVOUT=`echo $PARAM | awk ' { split($7, var, "=")
printf("%s", var[2]) }'`
eval COPNO=`echo $PARAM | awk ' { split($8, var, "=")
printf("%s", var[2]) }'`

export PARAM \
REQID \
LOGIN \
USRID \
USRNM \
PRINT \
SVOUT \
COPNO
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 03-29-2007
Registered User
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,397
Quote:
set $PARAM; shift; shift; shift; shift; shift; shift; shift; shift
If the number of shift commands is more than the number of parameters to your script then you will get the error shift: number is not correct.

Quote:
the line which is giving error is-
set $PARAM; shift; shift; shift; shift; shift; shift; shift; shift
I think you dont need set and shift commands.
Reply With Quote
  #3 (permalink)  
Old 03-31-2007
cfajohnson's Avatar
Registered User
 

Join Date: Mar 2007
Location: Toronto, Canada
Posts: 487
Quote:
Originally Posted by shrao
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 positional parameters from $N+1 ... are renamed to $1 ... If N is not given, it is assumed to be 1.
"
Quote:
the line which is giving error is-
set $PARAM; shift; shift; shift; shift; shift; shift; shift; shift

The is the same as:
Code:
shift 8
Have you checked whether there are as many as 8 parameters?
Quote:
Is it related somewhere to these parameters which is set before this line
PARAM=$*

What ARE you trying to do? What is the point of resetting the already existing parameters? And if you do it that way, you will also be performing word splitting on the parameters.

Quote:
case "$1" in
"-h"|"-H")
give_help
exit -1
;;
"-p"|"-P")
give_params
exit -1
;;
esac

eval REQID=`echo $PARAM | awk ' { split($2, var, "=")
printf("%s", var[2]) }'`
eval LOGIN=`echo $PARAM | awk ' { split($3, var, "=")
printf("%s", var[2]) }'`
eval USRID=`echo $PARAM | awk ' { split($4, var, "=")
printf("%s",var[2]) }'`
eval USRNM=`echo $PARAM | awk ' { split($5, var, "=")
printf("%s", var[2]) }'`
eval PRINT=`echo $PARAM | awk ' { split($6, var, "=")
printf("%s", var[2]) }'`
eval SVOUT=`echo $PARAM | awk ' { split($7, var, "=")
printf("%s", var[2]) }'`
eval COPNO=`echo $PARAM | awk ' { split($8, var, "=")
printf("%s", var[2]) }'`

export PARAM \
REQID \
LOGIN \
USRID \
USRNM \
PRINT \
SVOUT \
COPNO

I'm not going to correct that convoluted code. There are far too many things wrong with it.

Read the man page for your shell, and learn to use getopts.

Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 02:20 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