&& 與 || 配合 命令合併操作符 {} ...
&& 與 || 配合
eg:
cat test.sh
#!/bin/bash
[ -e /etc/hosts ] && echo "ok" || echo "fail"
bash test.sh
ok
eg:
cat test.sh
#!/bin/bash
[ -e /etc/hostssssss ] && echo "ok" || echo "fail"
bash test.sh
fail
註意這裡 && 必須在 || 之前
命令合併操作符 {}
[ -f /home/tecmint/Downloads/xyz1.txt ] || {touch /home/tecmint/Downloads/xyz.txt; echo "The file does not exist"}
“The file does not exist”