May 22, 2021 Linux
The echo instruction for the shell is similar to the echo instruction for PHP and is used for the output of strings. Command format:
echo string
You can use echo for more complex output format control.
echo "It is a test"
The double quotes here can be omitted, and the following command is consistent with 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 be omitted
The read command reads a line from the standard input and assigned 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 .sh, name receives the variables entered by the standard, and the result will be:
[root@www ~]# sh test.sh OK #标准输入 OK It is a test #输出
echo -e "OK!\n" # -e 开启转义 echo "It it a test"
Output:
OK! It it a test
#!/bin/sh echo -e "OK! \c" # -e 开启转义 \c 不换行 echo "It is a test"
Output:
OK! It is a test
echo "It is a test" > myfile
echo '$name\"'
Output:
$name\"
echo `date`
Note: Inverse quotes are
`
instead of single
'
.
The results show the current date
Sat Dec 9 14:41:48 CST 2017