In Linux, colon (:) is commonly used as the PATH separator (PATH) and data field separator (/etc/passwd. In fact, the colon (:) is also a built-in command in Bash. it does not do anything. it is an empty command and only serves as a position, but there are...
Description
In Linux, colons (:) are commonly used as PATH separators and data fields (/etc/passwd. In fact, the colon (:) is also a built-in command in Bash. it does not do anything. it is an empty command and only serves as a position, but sometimes it is needed. Of course, it also has its purpose, otherwise it does not need to exist. In the help page of Linux, it does not play any role except parameter extension and redirection.
Man: Write
: [Arguments]
No effect; the command does nothing beyond expanding arguments and specify Ming any specified redirections. A zero exit code is returned.
Common parameters
Format ::
· Do nothing, only act as a placeholder. For example, when writing a script, some syntax structures need to be composed of multiple parts, but the corresponding code is not ready or completed in the initial stage. in this case, you can use: as a placeholder, otherwise, an error is reported during execution.
Bash Code
If ["today" = "2011-08-29"]; then
:
Else
:
Fi
Format: your comment here
Format: # your comment here
Write code comments (single line comments ).
Format: 'Comment line1
Comment line2
More comments'
Write comments for multiple rows.
Format:> file
Format:> file
Clear the file content.
Format: $ {VAR: = DEFAULT}
If the VAR variable is not declared or NULL, set VAR to the DEFAULT value DEFAULT. If the following command is not added before, $ {VAR: = DEFAULT} is used as a command to execute the command. the error is correct.
Example
Example 1 parameter extension
[Root @ node56 ~] #: Abc= 1234
[Root @ node56 ~] # Echo $ abc
[Root @ node56 ~] #:$ {Abc: = 1234}
[Root @ node56 ~] # Echo $ abc
1234
[Root @ node56 ~] # $ {Abc: = 1234}
-Bash: 1234: command not found
[Root @ node56 ~] #
Example 2 clear an object
[Root @ node56 ~] # Cat <"Hello"> 123.txt
[Root @ node56 ~] # Cat 123.txt
Hello
[Root @ node56 ~] #:> 123.txt
[Root @ node56 ~] # Cat 123.txt
[Root @ node56 ~] #
Example 3: script comments and placeholders
Script test_colon.sh
Bash Code
#! /Bin/sh
: This is single line comment
: 'This is a multiline comment,
Second line
End of comments'
If ["1" = "1"]; then
Echo "yes"
Else
:
Fi
[Root @ node56 ~] #./Test_colon.sh
Yes
[Root @ node56 ~] #
This article is from "Bash @ Linux"