当前位置:网站首页>Echo command – output a string or extract the value of a shell variable

Echo command – output a string or extract the value of a shell variable

2022-06-25 05:59:00 ProYuan28

echo The command is used to output the extracted value of string or variable on the terminal device , This is Linux One of the most common commands in the system , But the operation is very simple .

People usually add... Before variables $ Extracting the value of a variable by means of symbols , for example :$PATH, And then use echo Command to output . Or use it directly echo Command outputs a string to the screen , Play the role of prompting users .

Grammar format :echo [ Parameters ] [ character string ]

Common parameters :

-n Don't output the ending newline
-e “\a” Sound a warning tone
-e “\b” Delete the preceding character
-e “\c” No newline at the end
-e “\f” Line break , The cursor stays in the original coordinate position
-e “\n” Line break , Move the cursor to the beginning of the line
-e “\r” Move the cursor to the beginning of the line , But don't wrap
-E No backslash transfer , And -e Parameter function is the opposite
—version View version information
--help View help information

Reference examples

Output a string :

[[email protected] ~]#  echo "LinuxCool.com" 
LinuxCool.com 

The extracted value of the output variable :

[[email protected] ~]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin

Escape the content , Not allow $ The function of extracting variable value of symbol takes effect :

[[email protected] ~]# echo \$PATH
$PATH

Combined with the output redirection character , Import string information into a file :

[[email protected] ~]# echo "It is a test" > linuxcool

Use backquotes to execute commands , And output the result to the terminal :

[[email protected] ~]# echo `date`

Output content with line breaks :

[[email protected] ~]# echo -e "a\nb\nc"
a
b
c

Delete a character from the output message , Look at the numbers 3 Vanished :

[[email protected] ~]# echo -e "123\b456" 
12456

 

原网站

版权声明
本文为[ProYuan28]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202201251057674.html