Understanding set

Many times, we may not pass arguments to the command line, but we may need to set parameters internally inside the script.

We can declare parameters with the set command, as follows:

$ set USA Canada UK France$ echo $1USA$ echo $2Canada$ echo $3UK$ echo $4France

We can use this inside the set_01.sh script, as follows:

set USA Canada UK France 
echo $1 
echo $2 
echo $3 
echo $4 

Run the script as this:

$ ./set.sh

The output is as follows:


Following is a summary of the declare options:




An array is created


Displays the function names and definitions


Displays only the function names


Makes the variables integer types


Makes the variables ...

Get Learning Linux Shell Scripting - Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.