Solved

What is the 'shift' command?

Posted on 1998-06-09
6
259 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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
File sharing syncing(Production to DR, DR back to Production) 2 29
Shell script errors 10 131
Linux: disable vim auto-comment 7 117
Install MySQL 5.6 and PHP on Centos Linux 6 119
In tuning file systems on the Solaris Operating System, changing some parameters of a file system usually destroys the data on it. For instance, changing the cache segment block size in the volume of a T3 requires that you delete the existing volu…
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 …
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
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.

776 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