Shell 的 echo 指令与 PHP 的 echo 指令相似,都是用于字符串的输出。命令格式:测试
echo stringspa
1.显示变量orm
#!/bin/sh read name echo "$name It is a test"
2.显示换行字符串
#!/bin/sh echo -e "OK! \c" # -e 开启转义 \c 不换行 echo "It is a test"
3.显示结果定向至文件string
echo "It is a test" > myfile
printf 命令的语法:table
printf format-string [arguments...]
参数说明:form
Shell中的 test 命令用于检查某个条件是否成立,它能够进行数值、字符和文件三个方面的测试。test
参数 | 说明 |
---|---|
-eq | 等于则为真 |
-ne | 不等于则为真 |
-gt | 大于则为真 |
-ge | 大于等于则为真 |
-lt | 小于则为真 |
-le | 小于等于则为真 |
实例演示:变量
num1=100 num2=100 if test $[num1] -eq $[num2] then echo '两个数相等!' else echo '两个数不相等!' fi