English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
The echo command in Shell is similar to the echo command in PHP, both of which are used for string output. Command format:
echo string
You can use echo to achieve more complex output format control.
echo "It is a test"
The double quotes can be omitted here. The following command has the same effect as the above example:
echo It is a test
echo "\"It is a test\""
The result will be:
"It is a test"
Similarly, double quotes can also be omitted
The read command reads a line from standard input and assigns the value of each field of the input line to the shell variable
#!/bin/sh read name echo "$name It is a test"
The above code is saved as test.sh, the variable name receives the standard input variable, and the result will be:
[root@www ~]# sh test.sh OK # Standard input OK It is a test # Output
echo -e "OK! \n" # -e Enable escaping echo "It is a test"
Output result:
OK! It is a test
#!/bin/sh echo -e "OK! \c" # -e Enable escaping \c No newline echo "It is a test"
Output result:
OK! It is a test
echo "It is a test" > myfile
echo '$name\"'
Output result:
$name\"
echo `date`
Note: Here we use backticks `, instead of single quotes '.
The result will display the current date
Thu Jul 24 10:08:46 CST 2018