Created
March 29, 2013 15:49
-
-
Save jamiekrug/5271680 to your computer and use it in GitHub Desktop.
IntelliJ IDEA template for Bash scripts. Notice all "$variable" strings must be escaped to "\$variable" to avoid IDEA new file prompt/placeholders.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
# Defaults. | |
opt_ex_a_no_arg=0 | |
opt_ex_b_with_arg="default" | |
usage() | |
{ | |
cat <<EOF | |
OVERVIEW | |
TODO | |
USAGE | |
$0 [ -a ] [ -b string ] [ -h ] | |
OPTIONS | |
-a Pass to turn on "a" option. | |
-b Pass, followed by argument, to override default "b" option (default: \$opt_ex_b_with_arg). | |
-h : Help (show this usage information). | |
EXAMPLES | |
# No options: | |
$0 | |
# Both options: | |
$0 -a -b \$opt_ex_b_with_arg | |
EOF | |
} | |
while getopts ":hab:" opt; do | |
case \$opt in | |
a) | |
opt_ex_a_no_arg=1 | |
;; | |
b) | |
opt_ex_b_with_arg="\$OPTARG" | |
;; | |
h) | |
usage; echo | |
exit 0 | |
;; | |
:) | |
echo "Option -\$OPTARG requires an argument." >&2; echo | |
usage; echo | |
exit 1 | |
;; | |
\?) | |
echo "Invalid option: -\$OPTARG" >&2; echo | |
usage; echo | |
exit 1 | |
;; | |
esac | |
done | |
if [ \$opt_ex_a_no_arg -eq 1 ]; then | |
echo "Option -a was passed, making variable opt_ex_a_no_arg=\$opt_ex_a_no_arg" | |
else | |
echo "Option -a was not passed; variable opt_ex_a_no_arg=\$opt_ex_a_no_arg" | |
fi | |
echo "Variable opt_ex_b_with_arg=\$opt_ex_b_with_arg" | |
echo "Done ($0)" | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment