echo命令会自动换行。
显示普通字符串
echo "this is string"
echo 'this is string'
echo this is string
显示字符的时候可以不加引号。
显示转义字符
echo "\"this is string\""
echo '\"this is string\"'
echo this is string\"
显示变量
a=888
echo the var of a is $a # the var of a is 888
换行和不换行
echo -e "OK! \n测试换行" # -e 开启转义
echo "hello"
echo -e "OK! 测试A \c 测试B" # -e 开启转义 \c 不换行
echo "hello"
显示内容重定向到文件
echo 将内容重定向到文件 > test.txt
这句代码会擦除test.txt中的内容并将字符串写入文件。
显示命令执行结果
echo `date`
echo `echo ---------------------`
echo `ls`
注意这里是反引号而不是单引号。