Solved

What is the 'shift' command?

Posted on 1998-06-09
6
269 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
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

 
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

When you do backups in the Solaris Operating System, the file system must be inactive. Otherwise, the output may be inconsistent. A file system is inactive when it's unmounted or it's write-locked by the operating system. Although the fssnap utility…
Why Shell Scripting? Shell scripting is a powerful method of accessing UNIX systems and it is very flexible. Shell scripts are required when we want to execute a sequence of commands in Unix flavored operating systems. “Shell” is the command line i…
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…
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.

632 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