[Bug 407] assign local vars and catch returncode

bugzilla at busybox.net bugzilla at busybox.net
Sat Jun 20 15:48:50 UTC 2009


https://bugs.busybox.net/show_bug.cgi?id=407





--- Comment #7 from Denys Vlasenko <vda.linux at googlemail.com>  2009-06-20 15:48:50 UTC ---
(In reply to comment #2)
> > Do you mean something like this?
> > 
> > myfunc() { local VAR="$(false)" || { echo FAIL; }; echo DONE; }; myfunc
> 
> yes, if 'false' means:
> an action, that produces a returncode != 0

No. 'false' is not something. Such command exists. It exits with exitcode 1.

My example was meant to be typed in at shell prompt literally, without any
modifications. That's what good bug report should do: provide exact recipe to
reproduce the bug. Yours wasn't exact.

> > I tested ash and hush and both match bash.
> 
> You are right, but this means that bash and hush are
> also affected - or is there a reason for "forgetting"
> the returncode?

First, if we match bash, it means we don't break scripts written for bash. This
is good regardless of whether bash behavior is correct or not.

Second, who says it should be preserved?

"local a=b" is not the same as "a=b".

"local a=b" is running a builtin called "local". Every builtin has exitcode,
just like normal commands. in this case it has exitcode 0: "I succeeded"

"a=b" is an assignment. It's not a command. It has no exitcode. IOW: exitcode
of the last command is preserved across "a=b".


-- 
Configure bugmail: https://bugs.busybox.net/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.


More information about the busybox-cvs mailing list