bash – pass arguments with flags to script
Pass arguments in any order, with ability to have some of the flags optional:
1 2 3 4 5 6 7 8 9 10 | while getopts u:d:p:f: option do case "${option}" in u) USER=${OPTARG};; d) DATE=${OPTARG};; p) PRODUCT=${OPTARG};; f) FORMAT=${OPTARG};; esac done |
*COLONS between flags indicate that the flag value is required. If a value is optional, OMIT the colon following the flag. e.g. udp:f: – means that u and d are optional.
Source: LIFEWIRE