shell学习五经常使用命令echo printf test

Shell echo命令

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

Shell printf 命令

printf 命令的语法:table

printf  format-string  [arguments...]

参数说明:form

  • format-string: 为格式控制字符串
  • arguments: 为参数列表。

Shell test命令

Shell中的 test 命令用于检查某个条件是否成立,它能够进行数值、字符和文件三个方面的测试。test

数值测试

参数 说明
-eq 等于则为真
-ne 不等于则为真
-gt 大于则为真
-ge 大于等于则为真
-lt 小于则为真
-le 小于等于则为真

实例演示:变量

num1=100
num2=100
if test $[num1] -eq $[num2]
then
    echo '两个数相等!'
else
    echo '两个数不相等!'
fi
相关文章
相关标签/搜索