In shell we have the command shift, but i saw on some example its giving shift 3
Why there is a number after shift ? and what its about ? what it does ?
Example:
echo “arg1= $1 arg2=$2 arg3=$3”
shift
echo “arg1= $1 arg2=$2 arg3=$3”
shift
echo “arg1= $1 arg2=$2 arg3=$3”
shift
echo “arg1= $1 arg2=$2 arg3=$3”
shift
The output will be:
arg1= 1 arg2=2 arg3=3
arg1= 2 arg2=3 arg3=
arg1= 3 arg2= arg3=
arg1= arg2= arg3=
But when i add that, it doesn't display it correctly.
Shift the positional parameters to the left by n. The positional parameters from n+1 ... $# are renamed to $1 ... $#-n. Parameters represented by the numbers $# to $#-n+1 are unset. n must be a non-negative number less than or equal to $#. If n is zero or greater than $#, the positional parameters are not changed. If n is not supplied, it is assumed to be 1. The return status is zero unless n is greater than $# or less than zero, non-zero otherwise.
shift
treat command line arguments as a FIFO queue, it popleft element every time it's invoked.bash - The advantage of shift over reassign value straightforward - Stack Overflow
Take a look at the man page, which says:
An Example script:
Run it:
This shows that after shifting by 3,
$1=four
,$2=five
and$3=six
.This would be answered simply by reading either the Bash manual, or typing
man shift
:you use
man bash
to find theshift
builtin command: