O'Reilly logo

Korn Shell: Unix and Linux Programming Manual, Third Edition, The by Anatole Olczak

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

The : Command

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required