3 ms·
In that third case, I find it crazy logic and confusing UX to have values with no space. If I type mysql -uroot on the command line, that should be equivalent t
by lucb1e 10y ago
In that third case, I find it crazy logic and confusing UX to have values with no space. If I type mysql -uroot on the command line, that should be equivalent to mysql -u -r -o -o -t but it's not.
- okdana 10y agoWell the argument parser knows that `-u` must take a value, and the only way it can really associate it with its value is positionally (i.e., the value is the stuff that immediately follows it). So it could force you to make the value a separate argument, but that would be a purely arbitrary restriction — it couldn't allow anything but the value to follow, so it'd just have to return an error for the sake of it. This behaviour is defined in POSIX, btw: >If the SYNOPSIS of a standard utility shows an option with a mandatory option-argument (as with [-c option_argument] in the example), a conforming application shall use separate arguments for that option and its option-argument. However, a conforming implementation shall also permit applications to specify the option and option-argument in the same argument string without intervening <blank> characters.
- lucb1e 10y agoOh, I had never thought of it like that. That makes sense! I just treated those commands (like mysql) as one of those commands where -every -option -must -be -separate. I suppose I don't mind that syntax anymore now. Thanks for changing my mind :)
- Annatar 10y agoIt is the (social contract) responsibility of the programmer to document in the usage and in the manual page that -u takes a username as an argument, and where such documentation exists, the convention is that username may be provided as -uuser or -u user. This is trivially achievable with getopts(1): while getopts u: Option do case "$Option" in u) User="$OPTARG" ;; esac done The colon tells getopts(1) that the -u option expects an argument. This behavior is also mandated by the POSIX specification.