Solved

What is the 'shift' command?

Posted on 1998-06-09
6
256 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
Comment Utility
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
Comment Utility
Can you give me an example??  Thanks
0
 
LVL 2

Author Comment

by:kellyjj
Comment Utility
Can you give me an example??  Thanks
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 84

Expert Comment

by:ozo
Comment Utility
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
Comment Utility
"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
Comment Utility
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

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

762 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

10 Experts available now in Live!

Get 1:1 Help Now