shell 编程 if for while 循环体语法
if 语句用法if [ $a == $b ]
then
echo "a is equal to b"
fi
if else 语句用法
a=10
b=20
if [ $a == $b ]
then
echo "a is equal to b"
else
echo "a is not equal to b"
fi
if elifelse 语句用法
a=10
b=20
if [ $a == $b ]
then
echo "a is equal to b"
elif [ $a -gt $b ]
then
echo "a is greater than b"
elif [ $a -lt $b ]
then
echo "a is less than b"
else
echo "None of the condition met"
fi
if test 语句两种用法
==================================================
if test $ -eq $; then echo 'The two numbers are equal!'; fi;
===================================================
num1=$
num2=$
if test $ -eq $
then
echo 'The two numbers are equal!'
else
echo 'The two numbers are not equal!'
fi
=================================================
if 条件表达式
文件表达式
if [ -ffile ] 如果文件存在
if [ ! -ffile ]如果文件不存在
if [ -d ... ] 如果目录存在
if [ -s file] 如果文件存在且非空
if [ -r file] 如果文件存在且可读
if [ -w file] 如果文件存在且可写
if [ -x file] 如果文件存在且可执行
整数变量表达式
if [ int1 -eq int2 ] 如果int1等于int2
if [ int1 -ne int2 ] 如果不等于
if [ int1 -ge int2 ] 如果>=
if [ int1 -gt int2 ] 如果>
if [ int1 -le int2 ] 如果
页:
[1]