Hasty Briefsbeta

Bilingual

Techniques Hacker News Uses to Create Great Shell Scripts

a year ago
  • #developer-tools
  • #bash
  • #shell-scripting
  • Make scripts interoperable and pipeline friendly by using #!/usr/bin/env bash, tput for portable color output, respecting $NO_COLOR, and outputting status messages to stderr.
  • Use printf instead of echo for more consistent behavior across different systems.
  • Utilize shellcheck to identify and fix common issues in shell scripts.
  • Understand the differences between double brackets [[]] and single brackets [] in Bash, with double brackets offering more features and safety.
  • Follow the convention of using exit code 2 for command line syntax errors.
  • Leverage bash boilerplates like bash3boilerplate to provide a solid foundation for scripts.