Re: [Bug 1857702] Re: " +=" operator does string concatenation for integer variables
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; echo $i 8 $ i=i+1; echo $i 9 ...yet, in mksh: $ i+=1; echo $i 91 That is clearly inconsistent. 'typeset -i' makes shell assignments interpret arithmetic expressions (as is documented in the manual page), and '+=' is just another form of shell assignment, therefore it should be changing the behaviour of '+=' as well as '='. ksh93, bash and zsh all act correctly here. mksh is a ksh clone and should be acting like ksh and all the others that have emulated ksh. - M. -- modernish -- harness the shell https://github.com/modernish/modernish
Re: [Bug 1857702] Re: " +=" operator does string concatenation for integer variables
On 27.12.19 23:02, Thorsten Glaser wrote: > and it’s most definitely not emulation of ksh93 > > some ksh88 and little parts of ksh93, but e.g. no float and other crap I've never used ksh88. so I do not know the intersection with ksh93. but my experience so far is that it seems easier to port a ksh93 script to mksh than to bash. so ... > or complicated things out of curiosity: what's on your "crap" list? what's on the "complicated" list regarding ksh93 (beyond compound variables ... ;))? personally, I wouldn't count ability of a "general purpose" scripting language to do floating point arithmetic as "crap". admittedly, I don't use that very often in ksh93 but it's good that it's there if needed (and calls to awk or whatever can be avoided). -- You received this bug notification because you are a member of mksh Mailing List, which is subscribed to mksh. Matching subscriptions: mkshlist-to-mksh-bugmail https://bugs.launchpad.net/bugs/1857702 Title: " +=" operator does string concatenation for integer variables Status in mksh: New Bug description: consider typeset -i x=0; x+=1; echo $x # → 1 (as in ksh/bash/zsh) but typeset -i x=1; x+=1; echo $x # → 11 (rather than 2 as in the other shells) I believe mksh should honour the integer declaration and interpret `+=' accordingly. currently, it does not even consistently use string concatentation (since the first example does not yield `01' ...). To manage notifications about this bug go to: https://bugs.launchpad.net/mksh/+bug/1857702/+subscriptions
Re: [Bug 1857702] Re: " +=" operator does string concatenation for integer variables
On 27.12.19 17:02, Thorsten Glaser wrote: > Erm… that’s right, += is string concatenation. ok, I got it that this seems to be the idea here, but 1. what about typeset -i x=0; x+=1; echo $x # → 1 (as in ksh/bash/zsh) if += categorically does string concat no matter what, should this not yield "01"? 2. the trio ksh93/bash/zsh all adjust the meaning of += to denoting integer addition/increment if the variable is declared integer. do you consider this "evil" and intentionally do not do it? it bit me when porting a somewhat elaborate script from ksh93 to mksh: suddenly 1+=1 yielded 11 rather than 2. I'm not sure what the "mission statement" of mksh is (if any) but I see that you come closer to ksh93 than bash in some regards (e.g. `set -A' and '${... ;}' command substitution are provided) and presume it is intended to emulate ksh93 where the latter is not manifestly broken? meaning: should mksh not follow the other shells (notably ksh) in how they handle += for integer variables? > > Write “let” before the line to make it integer addition. understood. thanks for pointing this out. I never so far hat any use for `let' ;) -- You received this bug notification because you are a member of mksh Mailing List, which is subscribed to mksh. Matching subscriptions: mkshlist-to-mksh-bugmail https://bugs.launchpad.net/bugs/1857702 Title: " +=" operator does string concatenation for integer variables Status in mksh: New Bug description: consider typeset -i x=0; x+=1; echo $x # → 1 (as in ksh/bash/zsh) but typeset -i x=1; x+=1; echo $x # → 11 (rather than 2 as in the other shells) I believe mksh should honour the integer declaration and interpret `+=' accordingly. currently, it does not even consistently use string concatentation (since the first example does not yield `01' ...). To manage notifications about this bug go to: https://bugs.launchpad.net/mksh/+bug/1857702/+subscriptions