Created
January 5, 2022 15:36
-
-
Save jecxjo/7889e6c14e68d98fd481ec759f5289d7 to your computer and use it in GitHub Desktop.
Easy way to print usage using awk
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/sh | |
# | |
# This is a test script | |
# | |
# Usage: easy-shell-usage.sh [<arguments>] | |
# | |
# There aren't any arguments available, but if there were they would be documented here. | |
# Anything in the first block of comments starting at the "Usage" line. | |
# Prints usage, but this comment won't be printed | |
usage() { | |
awk '/# Usage/{ x=1 } x==1 { print $0 } !/^#/ && x==1 { exit 0 }' $0 >&2 | |
exit 1 | |
} | |
test $# -gt 0 || usage | |
printf "Arguments: %s\n" "$@" | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment