shell脚本 &&运算符使用

 # 询问
ask() {
read -p "$1(y/n) >>> :" res
if [ "$res" == "y" ]; then
return 0
else
return 1
fi
}
ask "是否同意" && pwd

[command1] && [command2]
&&运算符会在命令command1为真时,执行命令command2,当两个命令都为真时,才会有结果输出

posted @ 2021-03-31 17:35  风哀伤  阅读(203)  评论(0编辑  收藏  举报