The : Command

   

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

Table of Contents
Chapter 9.  Miscellaneous Commands


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 loop continuously until fred is logged on.

 $ cat fred_test  while :  do        FRED=$(who | grep fred)        if [[ $FRED != "" ]]        then              print "Fred is here!"              exit        else              sleep 30        fi  done 

       
    Top
     



    Korn Shell. Unix and Linux Programming Manual, Third Edition
    Korn Shell. Unix and Linux Programming Manual, Third Edition
    ISBN: N/A
    EAN: N/A
    Year: 2000
    Pages: 177

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net