Shift Command
Shift Command
Shift is a built-in command in bash which after getting executed, shifts/move the
command line arguments to one position left.
The first argument is lost after using shift command.
This command takes only one integer as an argument.
This command is useful when you want to get rid of the command line arguments
which are not needed after parsing them.
Syntax:
shift n
Here, n is the number of positions by which you want to shift command-line
arguments to the left if you do not specify, the default value of n is assumed to be 1 i.e
shift works the same as shift 1.
Example: Let’s create a shell script file named as sampleshift.sh as follows. The total
number of command-line arguments is represented by $#. Use the following command
to create the desired shell script file
vi sampleshift.sh
Now paste the following code:
#!/bin/bash