简单示例

  1. // 通过shell脚本打开某个文件夹
  2. cd ~
  3. touch test.sh
  4. vim test.sh
  5. // 添加以下内容
  6. #!bin/bash
  7. cd desktop/study
  8. open ./
  9. chmod 775 ./test.sh
  10. ./test.sh

前端部署nginx

set -ex

  1. set -e // 这个参数的含义是,当命令发生错误的时候,停止脚本的执行
  2. #!/bin/bash
  3. echo 1 && rm non-existent-file && echo 2
  4. // 等同
  5. #!/bin/bash
  6. set -e
  7. echo 1
  8. rm non-existent-file # which will fail
  9. echo 2
  10. set -x // -x 参数的作用,是把将要运行的命令用一个 + 标记之后显示出来
  11. #!/bin/bash
  12. set -ex
  13. echo 1
  14. rm non-existent-file # which will fail
  15. echo 2
  16. // 输出
  17. + echo 1
  18. 1
  19. + rm non-existent-file
  20. rm: non-existent-file: No such file or directory