我绑在一起,让我的一些bash脚本在眼睛上更容易一些。假设我有这个脚本并且它工作正常。
if [ "$PASSWDCHECK" = "<title>401 Authorization Required</title>" ]
then echo "The Subsubscription password is wrong" ; exit
else mkdir /home/"$USERNAME"/src && mkdir /opt/logstash && mkdir /etc/snort && mkdir /etc/snort/rules/
fi
我想让它更像这样,但它无法执行。我错过了什么?
if [ "$PASSWDCHECK" = "<title>401 Authorization Required</title>" ]
then echo "The Subsubscription password is wrong" ; exit
else mkdir /home/"$USERNAME"/src &&
mkdir /opt/logstash &&
mkdir /etc/snort &&
mkdir /etc/snort/rules/ &&
fi
您需要
将放在每行的末尾,而不是放在
&&
之前。确保后没有空格。
只要&&
是该行的最后一个非空格标记,该命令将自动继续到下一行。
if [ "$PASSWDCHECK" = "<title>401 Authorization Required</title>" ]
then echo "The Subsubscription password is wrong" ; exit
else mkdir /home/"$USERNAME"/src &&
mkdir /opt/logstash &&
mkdir /etc/snort &&
mkdir /etc/snort/rules/
fi
&&
列表联接两个命令,因此解析器知道应丢弃第二个命令之前的换行符。
if [ "$PASSWDCHECK" = "<title>401 Authorization Required</title>" ]
then echo "The Subsubscription password is wrong" ; exit
else
mkdir /home/"$USERNAME"/src &&
mkdir /opt/logstash &&
mkdir /etc/snort &&
mkdir /etc/snort/rules/
fi