Home » Shell Scripting Shift through Parameters

Shell Scripting Shift through Parameters

by Online Tutorials Library

Shell Scripting Shift Through Parameters

Shift command is a built-in command. Command takes number as argument. Arguments shift down by this number.

For example, if number is 5, then $5 become $1, $6 become $2 and so on.

Example:

The shift command is mostly used when arguments are unknown. Arguments are processed in a while loop with a condition of (( $# )). this condition holds true as long as arguments are not zero. Number of arguments are reduced each time as the shift command executes.

Shell Scripting Shift through parameters 1

Look at the above snapshot, this is our script.

Shell Scripting Shift through parameters 2

Look at the above snapshot, this is the output of the above script.


read command

The read command allows a user to provide the runtime input.

Shell Scripting Shift through parameters 3

Look at the above snapshot, this is our script using read command.

Shell Scripting Shift through parameters 4

Look at the above snapshot, a user can enter the name in the shell.

You may also like