Solved

What is the 'shift' command?

Posted on 1998-06-09
6
258 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
  • 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Java performance on Solaris - Managing CPUs There are various resource controls in operating system which directly/indirectly influence the performance of application. one of the most important resource controls is "CPU".   In a multithreaded…
Every server (virtual or physical) needs a console: and the console can be provided through hardware directly connected, software for remote connections, local connections, through a KVM, etc. This document explains the different types of consol…
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…
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

911 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now