Linux and Networking

Linux and Networking

4.15. The shift command.

The shift command shifts the arguments passed to the script. For example, if I pass a series of parameters to a script, the shift 3 command would move the passed parameters 3 positions:

$1=$4 $2=$5 …

 

Let’s see how it works. We are going to make a script to which 6 parameters are passed. The script will show parameters 1, 2 and 3, then it will execute the shift 3 command and show parameters 1, 2 and 3 again (which will be 4, 5 and 6).

 

#!/bin/bash

echo “$1 $2 $3”

shift 3

echo “$1 $2 $3”

 

Suggested exercise.

Copy and run the above script. Check that it works.

The Demeter Project