if...fi语法

if [ expression ]
then
 Statement(s) to be executed if expression is true
fi​

注:expression左右有空格,最后必须以fi结尾。

if...else...fi语法

if [ expression ]
then
   Statement(s) to be executed if expression is true
else
   Statement(s) to be executed if expression is not true
fi

if...elif...fi语法

if [ expression 1 ]
then
   Statement(s) to be executed if expression 1 is true
elif [ expression 2 ]
then
   Statement(s) to be executed if expression 2 is true
elif [ expression 3 ]
then
   Statement(s) to be executed if expression 3 is true
else
   Statement(s) to be executed if no expression is true
fi
#!/bin/bash

a=10
b=10
if [ $a -lt $b ]
then
    echo "a lesser than b"
elif [ $a -eq $b ]
then
    echo "a equal to b"
else
    echo "a greater to b"
fi

作者:Gacfox
版权声明:本网站为非盈利性质,文章如非特殊说明均为原创,版权遵循知识共享协议CC BY-NC-ND 4.0进行授权,转载必须署名,禁止用于商业目的或演绎修改后转载。
Copyright © 2017-2024 Gacfox All Rights Reserved.
Build with NextJS | Sitemap