Detailed explanation of the echo command in CentOS

Source: Internet
Author: User
Echo function description: The echo command is the most common command used to print information. It is often used in command lines to print the value of environment variables. it is determined whether the specified environment variables are set in the current environment. In shell scripts, it is often used to print information and help debug programs. Parameter:-n. -E escapes strings. Escape characters available: a generates a warning; \ B deletes the previous character; \ c does not end with a line break; \ f returns a line break but the cursor remains at the original position; \ n line feed and move the cursor to the beginning of the line; \ r cursor echo

Function description:The echo command is the most commonly used command to print information. It is often used in command lines to print the value of environment variables. it is determined whether the specified environment variables are set in the current environment. In shell scripts, it is often used to print information and help debug programs.

Parameters:

-N: do not wrap the line after printing the information.

-E escapes strings.

Available escape characters:

A. send a warning;
\ B delete the previous character;
\ C does not end with a line break;
\ F line feed, but the cursor remains at the original position;
\ N wrap and move the cursor to the beginning of the line;
\ R move the cursor to the beginning of the line without line breaks;
\ T Insert tab;
\ V is the same as \ f;
\ Insert \ characters;
\ Nnn inserts the ASCII characters represented by nnn (octal;

Instance used:

(1) display the current PATH

[Root @ LiWenTong test4] # echo $ PATH

/Usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/bin:/usr/bin:/home/ato


(2) do not wrap the line after printing

[Root @ LiWenTong test4] # echo-n "pls input yourname:"; read name; echo "ths $ name" --- "read command indicates obtaining the variable value from the keyboard.

Pls input your name: atong

Ths atong

[Root @ linux-lwt tmp] # echo "pls inpu"; read name; echo "ths $ name"

Pls inpu

Atong

Ths atong

(3) escape characters

[Root @ LiWenTong test4] # echo-e "hello \ nword"

Hello

Word

[Root @ LiWenTong test4] # echo "hello \ nword"

Hello \ nword


(4) output to standard error output

When writing scripts, the pipeline often uses the output of the previous command as the input of the next command. if you want to print the debugging information, but do not interfere with the subsequent commands, you can output the debugging information to the standard error output, as shown below.

For example, [root @ LiWenTongtest4] # echo hello> & 2

Hello

The following are tips for using this method for script debugging on the Internet !!!

# Usage: proc_cmd

Proc_cmd ()

{

CMD = $1

NUM = $ (get_estimate_count $ CMD)

# Print the information only when a value is returned. Otherwise, an error occurs.

If ["$ NUM"]; then

Printf "%-48s \ t % 16s \ n" $ CMD $ NUM

Else

Echo $ CMD> & 2 --- à so that you can see whether the $ CMD information is what we want without affecting command execution.

Echo $ CMD> failed. dat

Fi

}

--------------------------- Subsequent self-Summary -----------------

Echo is simply a function of outputting content. there is no other function. Output variable echo $ variable


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.