【Shell】Shell命令学习记录(runoob)-echo命令&printf命令&test命令
Shell echo命令
Shell 的 echo 指令与 PHP 的 echo 指令类似,都是用于字符串的输出。命令格式:
echo string
1.显示普通字符串:
echo "It is a test"
这里的双引号完全可以省略,以下命令与上面实例效果一致:
echo It is a test
2.显示转义字符
echo "\"It is a test\""
结果将是:
"It is a test"
同样,双引号也可以省略
3.显示变量
read 命令从标准输入中读取一行,并把输入行的每个字段的值指定给 shell 变量
read name # 从输入框中接收输入变量
echo "$name It is a test"
以上代码保存为 test.sh,name 接收标准输入的变量,结果将是:
$ sh ./demo.sh
ok,
ok, It is a test
4.显示换行
echo -e "OK! \n" # -e 开启转义
echo "It is a test"
输出结果:
OK!
It is a test
echo "OK! \n" # 没有-e 开启转义时,显示内容为:
echo "It is a test"
输出结果:
OK! \n
It is a test
5.显示不换行
echo -e "OK! \c" # -e 开启转义 \c 不换行
echo