Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use the echo command in Linux

Shulou Source: shulou.com Published: 2022-06-02 00:37:03 10月15日 Update

Editor to share with you how to use the echo command in Linux, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

Detailed explanation of Linux:echo command

Used for string output

Format

Echo string

Use echo to achieve more complex output format control 1. Display the normal string: echo "It is a test" the double quotation marks here can be omitted, the following command is consistent with the above example: echo It is a test2. Displaying the escape character echo "\" It is a test\ "" will result in: "It is a test" similarly, double quotes can also be omitted by 3. The display variable read command reads one line from the standard input and assigns the value of each field on the input line to the shell variable #! / bin/shread name echo "$name It is a test". The above code is saved as the variable that test.sh,name receives the standard input. The result will be: [root@www ~] # sh test.shOK # standard input OK It is a test # output 4. Display the newline echo-e "OK!\ n" #-e to enable the escape echo "It it a test" output result: OK, it it a test5. Show no line break #! / bin/shecho-e "OK!\ c" #-e turn on escape\ c No line break echo "It is a test" output result: OK! It is a test

Transfer of meaning

\ a sound of warning

\ b Delete the previous character

\ c finally, no newline symbol is added.

\ f Wrap line, but the cursor remains in its original position

\ nWrap and the cursor moves to the beginning of the line

\ r move the cursor to the beginning of the line, but do not wrap

\ t insert tab

\ v is the same as\ f

\ insert\ character

\ nnn inserts ASCII characters represented by nnn (octal)

6. The display result is directed to the file echo "It is a test" > myfile7. Output the string as is, without escaping or taking variables (in single quotes) echo'$name\ "'output result: $name\" 8. Display the command execution results echo `date` the results will show the current date Thu Jul 24 10:08:46 CST 2014 above is "how to use echo commands in Linux" all the content of this article, thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Result character output command escape variable input cursor string quotation mark standard article content format complex ordinary same consistent one line not much Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS Shulou Technology Redmi OPPO Reno MySQL