Bash shift: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
No edit summary
 
(One intermediate revision by the same user not shown)
Line 9: Line 9:
=Overview=
=Overview=


This command one number as argument and shifts the [[Bash_Environment_Variables#Positional_Parameters_.241.2C_.242.2C_...|positional parameters]] to the left by that number. The positional parameters from n + 1 to [[Bash_Environment_Variables#.24.23|$#]] are renamed to variable names from $1 to $# - N+1.
This built-in command takes one number as argument and shifts the [[Bash_Built-In_Variables#Positional_Parameters_.241.2C_.242.2C_...|positional parameters]] to the left by that number. The positional parameters from n + 1 to [[Bash_Built-In_Variables#.24.23|$#]] are renamed to variable names from $1 to $# - n + 1. The first n positional parameters are thrown away.


Say you have a command that takes 10 arguments, and N is 4, then $4 becomes $1, $5 becomes $2 and so on. $10 becomes $7 and the original $1, $2 and $3 are thrown away.
If the number is not present, it is assumed to be 1.


If N is zero or greater than $#, the positional parameters are not changed (the total number of arguments, see Section 7.2.1.2) and the command has no effect. If N is not present, it is assumed to be
If n is zero or greater than [[Bash_Built-In_Variables#.24.23|$#]], the positional parameters are not changed and the command has no effect.
 
Also see

Latest revision as of 01:40, 24 September 2017

External

Internal

Overview

This built-in command takes one number as argument and shifts the positional parameters to the left by that number. The positional parameters from n + 1 to $# are renamed to variable names from $1 to $# - n + 1. The first n positional parameters are thrown away.

If the number is not present, it is assumed to be 1.

If n is zero or greater than $#, the positional parameters are not changed and the command has no effect.