Alex Rivera | Logout

What is the general syntax of a Unix shell command?

Asked 2010-01-29T05:32:07.783
16

In particular, why is that sometimes the options to some commands are preceded by a + sign and sometimes by a - sign?

for example:

sort -f
sort -nr
sort +4n
sort +3nr
Edit
Report

2 Answers

5

It's completely arbitrary; the command may implement all of the option handling in its own special way or it might call out to some other convenience functions. The getopt() family of functions is pretty popular, so most software written even remotely recently follows the conventions set by those routines. There are always exceptions, of course!

answered 2010-01-29T05:37:31.480
2

It's left to apps to parse options hence the inconsistency. Expanding on your sort example these are all equivalent for coreutils:

sort -k3
sort --k 3
sort --key 3
sort --key=3
_POSIX2_VERSION=199209 sort +2
answered 2010-01-29T14:49:23.930

Your Answer