&& 与 || 配合

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”

相关文章:

  • 2021-08-03
  • 2021-11-13
  • 2022-12-23
  • 2022-02-09
  • 2021-07-18
  • 2022-12-23
  • 2021-07-23
  • 2021-10-29
猜你喜欢
  • 2021-10-28
  • 2021-11-06
  • 2022-12-23
  • 2022-01-13
  • 2021-08-19
  • 2021-08-27
相关资源
相似解决方案