The null command

In many situations, we may need a command that does nothing and returns a success status such as 0. In such cases, we can use the null command. It is represented by a colon (:). For example, in the if loop, we do not want to add any command if it is successful, but we have certain commands to execute if it fails. In such situations, we can use the null command. This is illustrated in the following script. If we want to loop for ever, then the null command can be used in the for loop:

if grep "$city" city_database_file >& /dev/null 
      echo "City is not found in city_database_file " 
      exit 1 

Let's test the program:

    $ chmod +x
    $ ./

The following will be the output ...

Get Learning Linux Shell Scripting - Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.