Shell脚本中长语句换行

如下面shell判断语句很长且不易读,如能在适当位置换行则显得整齐易读,而换行的标准说法应当是

修改前:

单行长语句
1
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

修改后:

分行写的语句
1
2
3
4
5
6
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

操作步骤:

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