[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Differing behaviour of shells regarding simple commands with parameter assignments



Hi,

2012-12-26, 02:22:45 Cyril Brulebois wrote:
> Timo Weingärtner <timo@tiwe.de> (26/12/2012):
> > bash, zsh, posh output 121
> > 
> > busybox sh, dash, (m)ksh output 122
> > 
> > checkbashisms doesn't complain.
> > 
> > Which of the three is wrong? Where shall I file bugs?
> > 
> > When bar is not a function but an external script the output is 121
> > with all the shells.
> 
> you may want to check something like that:
>  
> http://pubs.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html#t
> ag_02_09_05

Thanks. If I read that correctly bash, zsh, posh are wrong, but I see that 
changing that might cause trouble.

As this might be a source for subtle errors, especially when external scripts 
are turned into shell functions or vice versa, would you find it useful to add 
a warning to checkbashisms?

Possible portable workarounds might be (depending on what is expected):
* foo=2; bar
* (foo=2 bar)
* oldfoo=$foo; foo=2; bar; foo=$oldfoo; unset oldfoo
with the last one hopefully being rarely needed.


Greetings
Timo

Attachment: signature.asc
Description: This is a digitally signed message part.


Reply to: