NetBSD-Bugs archive

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

Re: bin/54292: sh local variable assignment broken



The following reply was made to PR bin/54292; it has been noted by GNATS.

From: Robert Elz <kre%munnari.OZ.AU@localhost>
To: gnats-bugs%netbsd.org@localhost
Cc: 
Subject: Re: bin/54292: sh local variable assignment broken
Date: Thu, 13 Jun 2019 08:51:02 +0700

 And one more observation, if we change the script (f.sh) to be
 
 f() {
 l=local
 $l x=$(echo 1 2 3)
 echo $x
 y=$(echo 1 2 3)
 echo $y
 }
 
 then ...
 
 jinx$ bash -c '. /tmp/f.sh; f'
 /tmp/f.sh: line 3: local: `2': not a valid identifier
 /tmp/f.sh: line 3: local: `3': not a valid identifier
 1
 1 2 3
 
 (sh acts the same way as it did with the original, which is
 what should happen).
 
 Here that the command is the magic local (or declare or typeset
 or whatever it really is) is hidden from the bash parser.   It
 still runs the command (as it should) but only after it has processed
 the args using the same method that every other command gets.
 
 And for completeness, "export" "readonly" and anything else similar
 gets the same kind of treatment in bash - and not in sh.
 
 


Home | Main Index | Thread Index | Old Index