linux – What does colon mean in shell commands?


Sometimes I see the command : (colon) in sh commands, for example:

: | echo "hello"

The above command will execute successfully and display hello .

For the command : there is no manual page, but if you try to find out its path using which : we get

:: shell built-in command

What does this colon mean and what is it used for?


help on this built-in command can be read with the command

$ help :

most often this command can be found in such constructions:

  1. as a short and economical replacement for true :

    1. in infinite loops:

       while :; do ... done

      instead of:

       while true; do ... done
    2. in makefile recipes, if you want to ignore a non-zero command return code:

       команда_код_возврата_которой_не_важен || :

      instead of:

       команда_код_возврата_которой_не_важен || true

      or instead of:

  2. when you need to pass an empty string to the called program / command to its stdin :

     $ : | программа_ожидающая_получения_информации_на_stdin

    For example:

     $ : | openssl s_client ...
Scroll to Top