This totally makes sense in mksh only.
$ i=4+4; echo $i
This is an assignment of the string "4+4" to the variable i. The string
is then, between assignment and storage, parsed as an arithmetic
expression, because i is of integer type. The expression is calculated
and the result stored.
$ i=i+1;
Op 29-12-19 om 23:55 schreef Thorsten Glaser:
As discussed heavily on IRC, other shells can use ((…)) or let to work
like mksh, and the mksh behaviour is semantically correct.
Your position makes no sense, because in mksh (and ksh93, bash, zsh) you
can do things like:
$ typeset -i i
$ i=4+4;
maybe you can convince the `shellcheck' guys to support mksh ;).
but I was rather thinking of "error" as in "syntax error", i.e. disallow
+= on integers all together as being then easy to spot and repair. I am
somewhat paranoid about shells silently behaving differently, that's all
... :). for the
Warning reporting during running of a script is supremely hard, you
cannot use any file descriptors; basically, you have to reserve one with
a high number for syslog and do it that way and hope someone reads
syslog… so I never did. We really need a linting shell runner or
something ☹
--
You recei
thanks for making this discrepant behaviour of mksh more explicit in the
manpage/FAQ. I believe this is helpful (as, generally, a
"(in)compatibility table" comparing all relevant shells would be...).
regarding opening bugs all over the place in (at least) 3 other shells
for this issue: funny ;).