msh bug - backtick syntax doesn't set $?
John S. Skogtvedt
jss2k2 at chello.no
Mon Sep 4 18:54:41 CEST 2006
Test case:
dlginput=`dialog --stdout --inputbox Foo 0 0`
echo $?
Should echo 0 if OK was selected, 1 if Cancel was selected or 255 if the
escape key was pressed. In msh it always echoes 0.
I've made a small patch that tries to solve this:
http://home.chello.no/~jskogtv/msh.c.diff
The patch is against user/busybox/shell/msh.c .
From my testing (shell script with much dialog usage) it works OK.
I have to admit I don't fully understand how msh works, and there may be
a better way of solving it.
Here's what I know:
When the shell encounters `...` grave() is run.
Currently it doesn't capture the exit status.
After each command ("ls", "var=foo", etc) forkexec() sets $? to 0
unless a external command was run, in which case $? is set to the exit
status of the command.
What the patch does:
Captures the exit status in grave() and assigns it to a global variable
grave_exitstatus.
Checks for grave_exitstatus != -1 in forkexec(), and if so sets $? to
the exit status and sets grave_exitstatus to -1.
-------
Can you take a look at the patch, and if it looks OK, commit it?
Will make a bug report with busybox eventually (that is, if no one here
sees something wrong with the patch).
(I'm now subscribed to the list, no need to CC me.)
More information about the dslinux-devel
mailing list