第一种
if [ 条件判断式 ];then
程序
fi
第二种
if [ 条件判断式 ]
then
程序
fi
注意点
if使用fi结尾
举例子:判断当前的登录用户是不是root whoami 、 env | grep USER | cut -d "=" -f 2 取出user开头的一行,以=做分割取第二部分
#!/bin/bash
test=$(env | grep USER | cut -d "=" -f 2)
#变量一定要加上双引号"" ==前后也要加上双引号
if [ "$test" == "root" ];then
echo "当前用户是root"
fi