Use the echo command of linux to output a string or extract the value of a Shell variable
Today, the editor shares with you the use of linux's echo command to output strings or extract the value of Shell variables. I believe many people don't know much about it. In order to make you understand better, I summarized the following contents for you. Let's look down together. I'm sure you'll get something.
The echo command, which is used to output the extracted value of a string or variable on a terminal device, is one of the most commonly used commands in Linux systems, but the operation is very simple.
People usually extract the value of a variable by adding a $symbol to it, such as $PATH, and then output it with the echo command. Or directly use the echo command to output a string to the screen to give the user a hint.
Syntax format: echo [parameter] [string]
Common parameters:
Reference example
Output a string:
[root@linuxcool ~] # echo "LinuxCool.com"
LinuxCool.com
The extracted value of the output variable:
[root@linuxcool ~] # echo $PATH/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
Escape the content so that the function of extracting variable values of the $symbol does not take effect:
[root@linuxcool ~] # echo\ $PATH
$PATH
Import the string information into the file with the output redirector:
[root@linuxcool ~] # echo "It is a test" > linuxcool
Use backquotation marks to execute the command and output the result to the terminal:
[root@linuxcool ~] # echo `date`
Output content with newline characters:
[root@linuxcool ~] # echo-e "a\ nb\ nc" abc
Delete a character from the output and notice that the number 3 disappears:
[root@linuxcool] # echo-e "123\ b456"
12456 on the use of linux's echo command to output strings or extract the value of Shell variables is shared here, I hope that the above content can have a certain reference value for everyone, you can learn to apply. If you like this article, you might as well share it for more people to see.