Solved

What is the 'shift' command?

Posted on 1998-06-09
6
262 Views
Last Modified: 2010-08-05
What is the shift command??  I don't have the man pages, the command is being used in a dialup script (for dial access).  Syntax, etc....  thanks guys
0
Comment
Question by:kellyjj
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 2007795
assuming you're talking about sh

shift [n]
                The positional parameters from $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 $#.
0
 
LVL 2

Author Comment

by:kellyjj
ID: 2007796
Can you give me an example??  Thanks
0
 
LVL 2

Author Comment

by:kellyjj
ID: 2007797
Can you give me an example??  Thanks
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 84

Expert Comment

by:ozo
ID: 2007798
Didn't you say you had an example in a dialup script?


sh -c 'echo $1,$2,$3; shift; echo $1,$2,$3; shift 2; echo $1,$2,$3' - a b c d e f g
0
 
LVL 1

Accepted Solution

by:
zonker031798 earned 20 total points
ID: 2007799
"Shift" is a builtin to most shells, including sh and csh.
(In other words, this command is executed directly by the
shell itself, and is not run as a separate process a la
"cat", "ls", etc.)

Its function is to shift the parameters supplied to the shell
as arguments in order to move the next argument to the head
of the list.

For example, this script:

#!/bin/sh

echo $*
shift
echo $*

when run as follows:

/test-script 1 2 3 4

produces this output:

1 2 3 4
2 3 4

Shift is usually used in shell programs to parse arguments.
0
 
LVL 2

Author Comment

by:kellyjj
ID: 2007800
Very good answer.  Thanks.  Ozo,  thanks man.  I did have a script that had the command ,but the script wasn't working. Should have included that.  Sorry
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
CPU monthly average? 12 150
AIX    Volume group Auto ON/OFF question 2 147
AIX 5.x set up arrow to recall 11 71
leap year shell script 10 52
This tech tip describes how to install the Solaris Operating System from a tape backup that was created using the Solaris flash archive utility. I have used this procedure on the Solaris 8 and 9 OS, and it shoudl also work well on the Solaris 10 rel…
Using libpcap/Jpcap to capture and send packets on Solaris version (10/11) Library used: 1.      Libpcap (http://www.tcpdump.org) Version 1.2 2.      Jpcap(http://netresearch.ics.uci.edu/kfujii/Jpcap/doc/index.html) Version 0.6 Prerequisite: 1.      GCC …
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
Suggested Courses

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question