当前位置:主页 > 服务器 > Linux >

实例详解Linux 中的命令链接操作符

时间:2021-04-22 09:14:31 | 栏目:Linux | 点击:

&& 与 || 配合

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”

总结

您可能感兴趣的文章:

相关文章