4) Requesting User Input

Positional Parameters

The shell assigns numbers called 'positional parameters' to each command line argument that is entered. For example we use the cd (change directory to whichever directory you want to move to) or cp (type the file you want to copy and where you want to copy that file to). The feature that makes this possible is "positional parameters"

Example 1: Lets create a bash script "positional_script.sh #!/bash/bin echo "My name is $1" echo "Hy home directory is $2" echo "My favourite colour is $3" chmod 744 positional_script.sh

$#> positional_script.sh John $HOME blue

My name is John My home directory is /home/john My favourite colour is blue

The $1 $2 and $3 refer to the first, second and third command line arguments given to the script

Test bed

Last updated

Was this helpful?