Bash scripting doesn't have a defined way to interface with scripts. Usage strings, argument handling methods positional, shifting, and getopts consider expanding for C and Python
Usage/Help Message
Here is an example based on the NetBSD source code style guide:
Usage: program [-aDde] [-f | -g] [-n number] [-b b_arg | -c c_arg] req1 req2 [opt1 [opt2]]
This would indicate that "program" should be called with:
- options without operands: a, D, d, e (any of which may be omitted). Note that in this case some parameters are case-sensitive
- exclusive options: f, g (denoted by the vertical bar)
- options with operands: n
- exclusive options with operands: b, c
- required arguments: req1, req2
- optional argument opt1, which may be used with or without opt2 (marked optional within the group by using another set of square brackets)
- optional argument opt2, which requires opt1
Bash
Built-In Variables
$0
The Script Name
$1, $2, $3, ...
Positional Arguments
$#
Argument Count
$@ and $*
All the Args
Bash Test Function
16.3 test: Check file types and compare values
-z string
True if the length of string is zero.
-n string
True if the length of string is nonzero.
arg1 -eq arg2
equal
arg1 -ne arg2
not equal
arg1 -lt arg2
less then
arg1 -le arg2
less then equal
arg1 -gt arg2
greater then
arg1 -ge arg2
greater then equal
! TEST
boolean NOT
Basic Conditional Parsing
if ; then
fi
Loop shift parsing
getopts
Only supports shorthand single character options aka flags
aflag=
bflag=
while
do
done
if [; then
fi
if [; then
fi
getopt
Supports short and long options
#!/bin/bash
# We use "${@}" instead of "${*}" to preserve argument-boundary information
ARGS= ||
while ; do
done
remaining_args=("")