08test

shell test命令

数值

num1=100
num2=100
if test $[num1] -eq $[num2]
then
    echo '两个数相等!'
else
    echo '两个数不相等!'
fi

a=5
b=6

result=$[a+b] # 注意等号两边不能有空格
echo "result 为: $result"

字符

num1="ru1noob"
num2="runoob"
if test $num1 = $num2
then
    echo '两个字符串相等!'
else
    echo '两个字符串不相等!'
fi

文件

if test -e ./bash
then
    echo '文件已存在!'
else
    echo '文件不存在!'
fi

if test -e ./notFile -o -e ./bash
then
    echo '有一个文件存在!'
else
    echo '两个文件都不存在'
fi

posted on 2017-10-12 21:23  唐先生_DowneyJr  阅读(113)  评论(0编辑  收藏  举报

导航