Created
March 21, 2019 21:36
-
-
Save paulscott/f489a342bf94e73fa9022238f5f341a0 to your computer and use it in GitHub Desktop.
A simple way to output command usage for shell scripts
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 | |
# A one line description of what the command does | |
# | |
# Usage: | |
# commandName | |
# what this command does with no arguments | |
# commandName --argument [--optionalArg=value] | |
# what this command does with these arguments. one of them is optional. | |
# | |
# options: | |
# --someOption='val' : This option can apply to any invoation of the command. | |
function usage { | |
usageEnd=$((LINENO - 2)) | |
sed -n "2,${usageEnd}p;${usageEnd}q" "${0}" | sed 's/^#//' | |
} | |
# The usage function should be at the top of the file immediately after the usage comment. | |
# The sed one liner will output the comment and strip off the hash signs. | |
usage |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment