Skip to content

Instantly share code, notes, and snippets.

@iCross
Created May 15, 2023 11:38
Show Gist options
  • Save iCross/d1e02c886e98262fbb3105d04d2b442f to your computer and use it in GitHub Desktop.
Save iCross/d1e02c886e98262fbb3105d04d2b442f to your computer and use it in GitHub Desktop.
Optimizing Your Bash Scripts: An Advanced Template and Its Key Features. MIT license.
#!/usr/bin/env bash
set -o errexit
set -o nounset
set -o pipefail
if [[ "${DEBUG-0}" == "1" ]]; then
set -o xtrace
fi
print_help() {
echo "Usage: $0 input-file output-file
This script transforms the input file and writes the results to the output file.
"
}
if [[ "${1-}" =~ ^-*h(elp)?$ ]]; then
print_help
exit
fi
if [[ $# -ne 2 ]]; then
print_help
exit 1
fi
cd "$(dirname "$0")"
main() {
local input_file="$1"
local output_file="$2"
echo "Processing ${input_file} and saving results to ${output_file}"
}
main "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment