I have just tried the following look ... funny behaviour :
$ exec /usr/xpg4/bin/sh
$ let i++
/usr/xpg4/bin/sh: i++: bad number
$ let i+=1
/usr/xpg4/bin/sh: i+=1: bad number
$ i=0
$ let i++
/usr/xpg4/bin/sh: i++: more tokens expected
$ let i+=1
$ echo $i
1
$
---------- Post updated at 12:03 ---------- Previous update was at 12:00 ----------
It is a POSIX compliant shell and so are ksh93 and bash. It is just that it may have some additional features that are not POSIX compliant.. If you want your code to work universally in all POSIX compliant shells you should avoid using those features.
Yeah i meant : on my machine, where should i go to find a pure POSIX shell (no additional feature) ...( that was to test the "let" behaviour)
But anyway, i think that ... unless we meet special case (with strong cross system compatibility constraints and requirements) , i prefer to take advantage of the new fonctionalities offered by ksh or bash even if not purely POSIX compliant.
I do not think there is such a thing a pure POSIX compliant shell without additional features. Some shells aim to be. Of the shells I worked with dash comes closest I think.. I too prefer to take advantage of modern features and if I am working in an environment where that is not the problem, I will. Or if it is acceptable to compile or install superior ksh93 for every platform available, then fine.
But otherwise I restrict myself to POSIX compliant code, whenever possible.
A special case is this forum. To let solutions be of use in as many situations as possible, it is good practise to use POSIX compliant code, whether that is shell, awk, sed etc. If it is not, then it is good to mention that fact, for example you can state that it is GNU only of bash, ksh93, ksh, zsh etc.. That way you helping people who would otherwise waste time trying to reuse your code on their platform only to find out that it does not work..
It's added to SUS v3, that phrase is missing in v2.
When I posted the wrong correction, I didn't even checked, I was really sure, because I remember it's been pointed out many times by shell experts (or it's just my memory not serving right :)).
Thank you!
---------- Post updated at 01:25 PM ---------- Previous update was at 12:34 PM ----------
OK,
trying to understand where my confusion came from, I searched my mail archive
I suppose that the following information will be of interest only to limited number of forum members:
Perhaps it is good to note that IMO this does not contradict what I wrote above, since recent POSIX says that the dollar sign can only be left out if the shell variable x contains a value that forms a valid integer constant, which is not the case in this example.
I agree,
the main point was that there are old shells that require the preceding dollar sign.
---------- Post updated at 03:11 PM ---------- Previous update was at 02:41 PM ----------
Just to add that most probably the statement in SUS v3 that you indicated was added after S.C. expressed his opinion (see the next post in the c.u.s. thread by one of the authors of SUS.