Ksh Tutorials :Command Line Arguments in kshell

Ksh Tutorials :Command Line Arguments in kshell
It is also called "positional parameters"
The number of command line arguments is stored in $# so one can check
for arguments with:
if [[ $# -eq 0 ]];then
print "No Arguments"
The single Arguments are stored in $1, ....$n and all are in $* as one string. The arguments cannot
directly be modified but one can reset the hole commandline for another part of the program.
If we need a first argument $first for the rest of the program we do:
if [[ $1 != $first ]];then
set $first $*
One can iterate over the command line arguments with the help of the shift command. Shift indirectly removes the first argument.
until [[ $# -qe 0 ]];do
# commands ....
One can also iterate with the for loop, the default with for is $*:
for arg;do
print $arg
The program name is stored in $0 but it contains the path also!

No comments: