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

Get Korn Shell: Unix and Linux Programming Manual, Third Edition, The now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.