Linux commands I have used: (colon)-nothing else (......)

Source: Internet
Author: User
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"
 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.