One important "difference" is the XSI (XOPEN) option group, which specifies a number of traditional Unix interfaces which are unlikely to be applicable to a new operating system that's not "a Unix". Often people will use "SUS" to refer to the full standard including the XSI option, and "POSIX" to refer to the base standard and possibly the non-Unix-centric option groups.
Successive versions of SUS seem to be gradually deprecating parts of the XSI option that were not really useful for writing portable applications and that instead just reflected legacy implementations, and moving a few of the more-useful parts to the base standard.
In your first example, $((X+1))
evaluates the expression X + 1 and expands to the result, which is then asigned to the variable.
In the second example, $((X=X+1))
increments X
by one ($((X++))
is also valid and shorter, but not necessarily supported by the shell), then expands to the new value of $X
, which is the first argument to the null command, :
. The null command ignores its arguments, and the result is discarded (with side effects).
I would personally prefer the first form because of three (relatively subjective) reasons:
- The null command is obscure and misunderstood, as indicated by its often being the subject of confused questions here.
- The first form seems more natural in terms of overall shell grammar, and even resembles the old evaluation style a little bit.
- The first form is clearer and more concise and doesn't involve a command.
You'd have to use the first version if you were modifying the environment of just one command like
X=$((X+1)) /usr/local/bin/something
You'd have to use the second form to add evaluation to arguments directly:
ls -la "file-$((X++))" # or ...
ls -la "file-$((X=X+1))" # for better compatibility
This has the desired side effects, saves one line, and is pretty clear.
Best Answer
There is no difference.
hostname
anduname -n
output the same information. They both obtain it from theuname()
system call.One difference is that the
hostname
command can be used to set the hostname as well as getting it.uname
cannot do that. (Normally this is done only once, early in the boot process!)