The POSIX shell built-in : (colon) returns zero exit status and does nothing else. It is used in shell scripts in the following ways:
Without command-line arguments, it does exactly the same as the true command. This means that you can also create the condition true using the shell built-in :.
If you include arguments, the shell interprets all metacharacters that appear in them. This method of using the shell built-in : enables you to assign a default value to free shell variables without initiating any other action.
If you do not use any shell metacharacters in the command-line arguments, or if you escape them, the shell built-in : has the same function as the hash character #, i.e. it introduces comments. With :, though, unlike #, the next unescaped command separator terminates the comment.
Syntax
:[ argument...] |
Any string delimited by blanks or tabs. The last argument must be terminated by a command separator. You can specify any number of arguments, provided they are separated by at least one tab or blank. As with every other command, the string is first interpreted by the shell (see sh on "sh shell, the standard command language interpreter"). The shell built-in : returns only a zero exit status. argument not specified: |
Exit status
0 | in every case |
Example 1
You can use the shell built-in : to fill in a branch of an if or case construct if you do not want anything to happen in that branch. Suppose the shell script not_x contains the following: if test -x $1 then : else echo $1 is not executable! fi This shell script tests the file that you name as your first command-line argument. If the file is executable, the shell script does nothing; otherwise, the message “file is not executable!” is issued. |
Example 2
The following shell script assigns the process ID of the current shell process to the shell variable name if this variable is undefined or contains the null string: : ${name:=$$} echo $name |
See also
true |