January 2001
Intermediate to advanced
480 pages
7h 22m
English
The : command is the null command. If specified, arguments are expanded. It is typically used as a no-op, to check if a variable is set, or for endless loops. The : command here is used to check if LBIN is set.
$ : ${LBIN:?} LBIN: parameter null or not set
If given in a Korn shell script, it would cause it to exit with an error if LBIN was not set.
This example counts the number of lines in the file ftext, then prints the total. The : command is used as a no-op, since we only want to print the total number of lines after the entire file has been read, not after each line.
$ integer NUM=0 $ exec 0<ftext && while read LINE && ((NUM+=1)) > do > : > done; print $NUM 7
In the following Korn shell script, the : command is used to ...
Read now
Unlock full access