Positional parameters set

From assela Pathirana
Jump to navigationJump to search
Green info.gif

The commands on this page can be tried out on Cygwin installed in a windows PC or on any UNIX computer.

Following is an example of positional parameters created by command line arguments being later replaced by others.

#!/bin/bash
#try calling this with several arguments
echo '$1=' $1
echo '$2=' $2
echo '$3=' $3
set `ls`
echo '$1=' $1
echo '$2=' $2
echo '$3=' $3

The first echo statements will print the command line arguments; but the second set will print the first three files in the current directory! The set command replace the positional parameters with the output of ls command.