shell脚本中语句太长时,换行操作

  如下面shell判断语句很长且不易读,如能在适当位置换行则显得整齐易读。

修改前:


if cat /etc/SuSE-release | grep -i "suse" >/dev/null 2>&1 && [ `cat /etc/SuSE-release | grep "VERSION" | awk '{print $3}'` == "12" ] && [ `cat /etc/SuSE-release |grep "PATCHLEVEL" | awk '{print $3}'` == "4" ];then
     echo "This system is SUSE 12 SP4"
else
     echo "This system is noe SUSE 12 SP4"
fi


修改后:

if cat /etc/SuSE-release | grep -i "suse" >/dev/null 2>&1 && \
[ `cat /etc/SuSE-release | grep "VERSION" | awk '{print $3}'` == "12" ] && \
[ `cat /etc/SuSE-release |grep "PATCHLEVEL" | awk '{print $3}'` == "4" ];then
     echo "This system is SUSE 12 SP4"
else
     echo "This system is noe SUSE 12 SP4"
fi

操作步骤:

在需要换行的位置加 "\" ,然后直接按回车键

你可能感兴趣的:(shell)