Bash programming/Parsing Command-Line Arguments
Appearance
Parsing command-line argument can be done at least using three different methods[1]
- Using
getopt[s]
- Bash Space-Separated (e.g., --option argument) (without getopt[s])
- Bash Equals-Separated (e.g., --option=argument) (without getopt[s])
Basic usage template:
#!/bin/bash program_name=$0 function usage { echo "Usage: $program_name [parameter1] [parameter2] [parameter3]" echo " parameter1 - parameter 1 explanation" echo " parameter2 - parameter 2 explanation" echo " Example: $program_name parameter1 parameter2 parameter3" exit 1 } if [ $# == 0 ]; then usage fi
See also
[edit | edit source]- Bash Positional Parameters https://www.gnu.org/software/bash/manual/html_node/Positional-Parameters.html
- go
fmt.Scanln
function - bargs - Wrap your Bash script with command line arguments