当前位置: 移动技术网 > 网络运营>服务器>Linux > 实例详解Linux 中的命令链接操作符

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

2019年04月19日  | 移动技术网网络运营  | 我要评论

&& 与 || 配合

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”

总结

以上所述是小编给大家介绍的linux 中的命令链接操作符,希望对大家有所帮助

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网