bashscript 999 B

1234567891011121314151617181920212223242526272829
  1. #!/bin/bash
  2. #
  3. # The Unofficial "Bash Strict Mode".
  4. #
  5. # -e Failed commands exit.
  6. # -u Unbound variables exit.
  7. # -o pipefail Do not hide piped-command failures.
  8. # IFS=$'\n\t' Newline/Tab separators are good for loops and names with spaces.
  9. #
  10. # Tips:
  11. #
  12. # 1. Avoid unset (unbound) variables. Use default values for:
  13. # - Positional parameters e.g. `${1:-}`.
  14. # - Potentially undefined variables e.g. `${ENVVAR:-}`.
  15. # - Intentionally empty/undefined variables e.g. `MAYBE_EMPTY=""`.
  16. #
  17. # 2. Failed Commands will stop the script. Avoid this by affixing ` || true`.
  18. #
  19. # 3. Strict Options can be toggled, if really required:
  20. # - Switch off: `set +opt`. Switch back on afterwards: `set -opt`.
  21. # - Toggle `-e` if the previous return value (`$?`) is needed.
  22. # - Toggle `-u` if sourcing a non-conforming script.
  23. #
  24. # 4. Exit Traps can perform try-catch-finally-like clean-up tasks.
  25. #
  26. # (These comments are all removed when vim loads this template.)
  27. #
  28. set -euo pipefail
  29. IFS=$'\n\t'