shell脚本中的&&解析

#!/bin/bash
touch file1
# 创建文件file1
rm -f file2
# 删除文件file2
if [ -f file1 ] && echo "hello" && [ -f file2 ] && echo "world"
# 如果文件file1存在,则输出"hello" 
# 如果前面的命令(即echo "hello")执行成功,则继续判断是否存在文件file2
# 如果文件file2存在,则输出"world"
# 如果前面的命令(即echo "world")执行成功,则继续执行then echo "in if"
then
	echo "in if"
# 如果前面的命令(即echo "world")执行失败,则继续执行then echo "in else"
else
	echo "in else"
fi
exit 0

输出结果为

posted @ 2023-04-18 14:32  七色彩虹k  阅读(120)  评论(0)    收藏  举报