Skip to content

Instantly share code, notes, and snippets.

@bertvv
Last active September 16, 2024 17:12
Show Gist options
  • Save bertvv/7727082 to your computer and use it in GitHub Desktop.
Save bertvv/7727082 to your computer and use it in GitHub Desktop.
Simple Bash script template
#!/bin/bash
#
# Script name -- purpose
#
# Author:
set -o errexit # abort on nonzero exitstatus
set -o nounset # abort on unbound variable
set -o pipefail # don't hide some errors in pipes
#
# Functions
#
# Print usage info
usage() {
cat << _EOF_
Usage: ${0}
_EOF_
}
#
# Variables
#
#
# Command line parsing
#
if [ "$#" -ne "1" ]; then
echo "Expected 1 argument, got $#" >&2
usage
exit 2
fi
#
# Script proper
#
@AhmadAlhajKarim
Copy link

Waarom moeten wij in line 30 de stdout dwingen naar stderr ? Heeft het echt nut?

@bertvv
Copy link
Author

bertvv commented Sep 16, 2024

Het commando op lijn 30 drukt een foutboodschap af, dus het is nuttig dit naar stderr af te drukken om een onderscheid te maken met de "normale" output van het script.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment