Sponsored Content
Top Forums Shell Programming and Scripting Regarding the shift command??? Post 302112843 by cfajohnson on Saturday 31st of March 2007 03:39:54 AM
Old 03-31-2007
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.

 

10 More Discussions You Might Find Interesting

1. 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

2. UNIX for Dummies Questions & Answers

xterm SHIFT crazy

hi all, when I press SHIFT at once it work like as I've hold it (like CapsLock is On, but it Off) ! ... and if I press F1 (or another function key) it put out 24z :( it is occure on my remote sun 8 , xterm session help me please ! (2 Replies)
Discussion started by: oneivan
2 Replies

3. 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

4. UNIX for Dummies Questions & Answers

shift not working

Hi, I wrote one script, in between script needs to use 10th and 11th positional parameters, that time i used "shift". Here i am facing the below find problem, ./DataCount.sh: cannot shift I tried 1) I have read man pages for shift 2) Before but * and ** 3) Simple shift with out giving... (4 Replies)
Discussion started by: Nagapandi
4 Replies

5. 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

6. UNIX for Dummies Questions & Answers

A Shift into UNIX

Hi, Firstly, I did a search for this question both on this site and on the internet and have not been able to find a suitable answer that is not general in nature. I have always been a Windows user. I use my girl friend's mac every now and then, but I always come back to windows. For a... (1 Reply)
Discussion started by: mearex
1 Replies

7. 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

8. UNIX for Dummies Questions & Answers

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! (1 Reply)
Discussion started by: me.
1 Replies

9. Shell Programming and Scripting

AIX function example with "shift" command

Hello, I am reading one of the AIX manuals about shell scripting and (AIX 5) and I found this example when introducing to functions: function usage { prog="$1"; shift print -u2 "$prog: usage: $prog $@" exit 1 } This example is meant to be easy but I don't understand what it is... (5 Replies)
Discussion started by: Kibou
5 Replies

10. 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
shift(1)							   User Commands							  shift(1)

NAME
shift - shell built-in function to traverse either a shell's argument list or a list of field-separated words SYNOPSIS
sh shift [n] csh shift [variable] ksh *shift [n] ksh +shift [n] DESCRIPTION
sh The positional parameters from $n+1 ... are renamed $1 ... . If n is not specified, it is assumed to be 1. csh The components of argv, or variable, if supplied, are shifted to the left, discarding the first component. It is an error for the variable not to be set or to have a null value. ksh The positional parameters from $n+1 $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 $#. On this manual page, ksh(1) commands that are preceded by one or two * (asterisks) are treated specially in the following ways: 1. Variable assignment lists preceding the command remain in effect when the command completes. 2. I/O redirections are processed after variable assignments. 3. Errors cause a script that contains them to abort. 4. Words, following a command preceded by ** that are in the format of a variable assignment, are expanded with the same rules as a variable assignment. This means that tilde substitution is performed after the = sign and word splitting and file name genera- tion are not performed. ksh93 shift is a shell special built-in that shifts the positional parameters to the left by the number of places defined by n, or 1 if n is omitted. The number of positional parameters remaining is reduced by the number of places that are shifted. If n is specified, it is evaluated as an arithmetic expression to determine the number of places to shift. It is an error to shift more than the number of positional parameters or a negative number of places. The following exit values are returned by shift in ksh93: 0 Successful completion. The positional parameters were successfully shifted. >0 An error occurred. On this manual page, ksh93(1) commands that are preceded by one or two + are treated specially in the following ways: 1. Variable assignment lists preceding the command remain in effect when the command completes. 2. I/O redirections are processed after variable assignments. 3. Errors cause a script that contains them to abort. 4. They are not valid function names. 5. Words, following a command preceded by ++ that are in the format of a variable assignment, are expanded with the same rules as a variable assignment. This means that tilde substitution is performed after the = sign and field splitting and file name genera- tion are not performed. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWcsu | +-----------------------------+-----------------------------+ SEE ALSO
csh(1), ksh(1), ksh93(1), sh(1), attributes(5) SunOS 5.11 20 Nov 2007 shift(1)
All times are GMT -4. The time now is 04:48 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy