Passing arguments to shell scripts
To pass an argument to a shell script from the command line, simply follow the shell command with your argument:
Unix makes using the arguments in your shell script just as easy with some pre-defined variables:
For instance, say I have the following shell script called myShell.ksh:
Executing the script with the command
would produce the following output:
$ myShell.ksh arg1
Unix makes using the arguments in your shell script just as easy with some pre-defined variables:
$# - the number of arguments passed
$* - all arguments passed
$0 - the command run from the Unix prompt
$1 - $9 - argument one through nine passed ot the script
For instance, say I have the following shell script called myShell.ksh:
echo "This is myShell.ksh"
echo $#
echo $*
echo $0
echo $1
echo $2
Executing the script with the command
$ myShell.ksh bob smith
would produce the following output:
This is myShell.ksh
2
bob smith
myShell.ksh
bob
smith
Comments