* [U-Boot] HUSH logical AND/OR expressions
@ 2015-04-27 13:39 Joakim Tjernlund
2015-04-28 18:00 ` Joe Hershberger
0 siblings, 1 reply; 8+ messages in thread
From: Joakim Tjernlund @ 2015-04-27 13:39 UTC (permalink / raw)
To: u-boot
Trying to get a better handle of HUSH shell expressions, this does not work as I expect:
=> false && true || echo ECHO
=> false && false || echo ECHO
none prints ECHO, seems like a bug?
This the only one that prints ECHO
>= true && false || echo ECHO
Jocke
^ permalink raw reply [flat|nested] 8+ messages in thread
* [U-Boot] HUSH logical AND/OR expressions
2015-04-27 13:39 [U-Boot] HUSH logical AND/OR expressions Joakim Tjernlund
@ 2015-04-28 18:00 ` Joe Hershberger
2015-04-28 18:19 ` James Chargin
0 siblings, 1 reply; 8+ messages in thread
From: Joe Hershberger @ 2015-04-28 18:00 UTC (permalink / raw)
To: u-boot
Hi Joakim,
On Mon, Apr 27, 2015 at 8:39 AM, Joakim Tjernlund
<joakim.tjernlund@transmode.se> wrote:
> Trying to get a better handle of HUSH shell expressions, this does not work as I expect:
> => false && true || echo ECHO
> => false && false || echo ECHO
>
> none prints ECHO, seems like a bug?
I think it works as it should. false followed by && will terminate always.
> This the only one that prints ECHO
>>= true && false || echo ECHO
This also seems correct. Passing true into && and false into || will
always continue.
Cheers,
-Joe
^ permalink raw reply [flat|nested] 8+ messages in thread
* [U-Boot] HUSH logical AND/OR expressions
2015-04-28 18:00 ` Joe Hershberger
@ 2015-04-28 18:19 ` James Chargin
2015-04-28 18:35 ` Joe Hershberger
0 siblings, 1 reply; 8+ messages in thread
From: James Chargin @ 2015-04-28 18:19 UTC (permalink / raw)
To: u-boot
Dear Joe Hershberger,
On 04/28/2015 11:00 AM, Joe Hershberger wrote:
> Hi Joakim,
>
> On Mon, Apr 27, 2015 at 8:39 AM, Joakim Tjernlund
> <joakim.tjernlund@transmode.se> wrote:
>> Trying to get a better handle of HUSH shell expressions, this does not work as I expect:
>> => false && true || echo ECHO
>> => false && false || echo ECHO
>>
>> none prints ECHO, seems like a bug?
>
> I think it works as it should. false followed by && will terminate always.
>
>> This the only one that prints ECHO
>>> = true && false || echo ECHO
>
> This also seems correct. Passing true into && and false into || will
> always continue.
>
I thought hush is supposed to be mostly similar to sh. On my Linux
desktop, bash (which is supposed to be backward compatible with sh) says
$ which sh
/usr/bin/sh
$ ls -l /usr/bin/sh
lrwxrwxrwx 1 root root 4 Apr 17 14:43 /usr/bin/sh -> bash
$ sh --version
GNU bash, version 4.2.46(1)-release (x86_64-redhat-linux-gnu)
Copyright (C) 2011 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later
<http://gnu.org/licenses/gpl.html>
This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
$ sh
sh-4.2$ false && true || echo ECHO
ECHO
sh-4.2$ false && false || echo ECHO
ECHO
sh-4.2$ true && false || echo ECHO
ECHO
sh-4.2$ exit
exit
Is this one of the places where hush and sh are not the same?
Regards,
Jim
--
Jim Chargin
AJA Video Systems jimc at aja.com
(530) 271-3334 http://www.aja.com
^ permalink raw reply [flat|nested] 8+ messages in thread
* [U-Boot] HUSH logical AND/OR expressions
2015-04-28 18:19 ` James Chargin
@ 2015-04-28 18:35 ` Joe Hershberger
2015-04-28 19:13 ` James Chargin
0 siblings, 1 reply; 8+ messages in thread
From: Joe Hershberger @ 2015-04-28 18:35 UTC (permalink / raw)
To: u-boot
Hi James,
On Tue, Apr 28, 2015 at 1:19 PM, James Chargin <jimccrown@gmail.com> wrote:
> Dear Joe Hershberger,
>
> On 04/28/2015 11:00 AM, Joe Hershberger wrote:
>>
>> Hi Joakim,
>>
>> On Mon, Apr 27, 2015 at 8:39 AM, Joakim Tjernlund
>> <joakim.tjernlund@transmode.se> wrote:
>>>
>>> Trying to get a better handle of HUSH shell expressions, this does not
>>> work as I expect:
>>> => false && true || echo ECHO
>>> => false && false || echo ECHO
>>>
>>> none prints ECHO, seems like a bug?
>>
>>
>> I think it works as it should. false followed by && will terminate always.
>>
>>> This the only one that prints ECHO
>>>>
>>>> = true && false || echo ECHO
>>
>>
>> This also seems correct. Passing true into && and false into || will
>> always continue.
>>
>
> I thought hush is supposed to be mostly similar to sh. On my Linux desktop,
> bash (which is supposed to be backward compatible with sh) says
>
> $ which sh
> /usr/bin/sh
> $ ls -l /usr/bin/sh
> lrwxrwxrwx 1 root root 4 Apr 17 14:43 /usr/bin/sh -> bash
> $ sh --version
> GNU bash, version 4.2.46(1)-release (x86_64-redhat-linux-gnu)
> Copyright (C) 2011 Free Software Foundation, Inc.
> License GPLv3+: GNU GPL version 3 or later
> <http://gnu.org/licenses/gpl.html>
>
> This is free software; you are free to change and redistribute it.
> There is NO WARRANTY, to the extent permitted by law.
> $ sh
> sh-4.2$ false && true || echo ECHO
> ECHO
> sh-4.2$ false && false || echo ECHO
> ECHO
> sh-4.2$ true && false || echo ECHO
> ECHO
> sh-4.2$ exit
> exit
>
> Is this one of the places where hush and sh are not the same?
The way hush seems to work is it drops out of the entire command if a
case is false.
Looking at the code in the hush parser, it seems at face value like it
should be skipping the command and then picking up the next command
(echo), but it clearly doesn't.
if ( (rcode==EXIT_SUCCESS && pi->followup==PIPE_OR) ||
(rcode!=EXIT_SUCCESS && pi->followup==PIPE_AND) )
skip_more_in_this_rmode=rmode;
I always just assumed this was a limitation of hush, but it's now
looking like a bug instead.
I haven't debugged into it, but I tend to stay away from hush these
days. When I've submitted a bug fix to this area I've been told that
we should upgrade wholesale instead, and I've haven't been up for that
task so far. http://lists.denx.de/pipermail/u-boot/2012-November/139841.html
Perhaps there is an easy, minor bugfix for this that would be palette-able.
-Joe
^ permalink raw reply [flat|nested] 8+ messages in thread
* [U-Boot] HUSH logical AND/OR expressions
2015-04-28 18:35 ` Joe Hershberger
@ 2015-04-28 19:13 ` James Chargin
2015-04-28 19:47 ` Joe Hershberger
0 siblings, 1 reply; 8+ messages in thread
From: James Chargin @ 2015-04-28 19:13 UTC (permalink / raw)
To: u-boot
Dear Joe,
On 04/28/2015 11:35 AM, Joe Hershberger wrote:
> Hi James,
>
> On Tue, Apr 28, 2015 at 1:19 PM, James Chargin <jimccrown@gmail.com> wrote:
>> Dear Joe Hershberger,
>>
>> On 04/28/2015 11:00 AM, Joe Hershberger wrote:
>>>
>>> Hi Joakim,
>>>
>>> On Mon, Apr 27, 2015 at 8:39 AM, Joakim Tjernlund
>>> <joakim.tjernlund@transmode.se> wrote:
>>>>
>>>> Trying to get a better handle of HUSH shell expressions, this does not
>>>> work as I expect:
>>>> => false && true || echo ECHO
>>>> => false && false || echo ECHO
...
>
> I always just assumed this was a limitation of hush, but it's now
> looking like a bug instead.
>
> I haven't debugged into it, but I tend to stay away from hush these
> days. When I've submitted a bug fix to this area I've been told that
> we should upgrade wholesale instead, and I've haven't been up for that
> task so far. http://lists.denx.de/pipermail/u-boot/2012-November/139841.html
That's a great conversation with Wolfgang, thanks for the reference.
Like you, I have tended to use hush carefully. It is similar to sh/bash,
but different enough that I never count on an easy port of bash script
fragments.
I noticed you asked for a reference to the original hush code that is
the origin for U-Boot's adaptation. I couldn't find a reply to that
question. I also haven't been able to find anything with a quick we
search. Do you know where it did come from?
>
> Perhaps there is an easy, minor bugfix for this that would be palette-able.
I've been "afraid" of the hush code for a while. I don't think I want to
mess with it now. I'll just continue to work with what we've got, carefully.
Thanks again for your attention,
Jim
^ permalink raw reply [flat|nested] 8+ messages in thread
* [U-Boot] HUSH logical AND/OR expressions
2015-04-28 19:13 ` James Chargin
@ 2015-04-28 19:47 ` Joe Hershberger
2015-04-28 22:51 ` Wolfgang Denk
0 siblings, 1 reply; 8+ messages in thread
From: Joe Hershberger @ 2015-04-28 19:47 UTC (permalink / raw)
To: u-boot
Hi James,
On Tue, Apr 28, 2015 at 2:13 PM, James Chargin <jimccrown@gmail.com> wrote:
> Dear Joe,
>
> On 04/28/2015 11:35 AM, Joe Hershberger wrote:
>>
>> Hi James,
>>
>> On Tue, Apr 28, 2015 at 1:19 PM, James Chargin <jimccrown@gmail.com>
>> wrote:
>>>
>>> Dear Joe Hershberger,
>>>
>>> On 04/28/2015 11:00 AM, Joe Hershberger wrote:
>>>>
>>>>
>>>> Hi Joakim,
>>>>
>>>> On Mon, Apr 27, 2015 at 8:39 AM, Joakim Tjernlund
>>>> <joakim.tjernlund@transmode.se> wrote:
>>>>>
>>>>>
>>>>> Trying to get a better handle of HUSH shell expressions, this does not
>>>>> work as I expect:
>>>>> => false && true || echo ECHO
>>>>> => false && false || echo ECHO
>
>
> ...
>
>>
>> I always just assumed this was a limitation of hush, but it's now
>> looking like a bug instead.
>>
>> I haven't debugged into it, but I tend to stay away from hush these
>> days. When I've submitted a bug fix to this area I've been told that
>> we should upgrade wholesale instead, and I've haven't been up for that
>> task so far.
>> http://lists.denx.de/pipermail/u-boot/2012-November/139841.html
>
>
> That's a great conversation with Wolfgang, thanks for the reference.
>
> Like you, I have tended to use hush carefully. It is similar to sh/bash, but
> different enough that I never count on an easy port of bash script
> fragments.
>
> I noticed you asked for a reference to the original hush code that is the
> origin for U-Boot's adaptation. I couldn't find a reply to that question. I
> also haven't been able to find anything with a quick we search. Do you know
> where it did come from?
I never got a response, but it appears to be busybox...
http://git.busybox.net/busybox/tree/shell/hush.c
>>
>> Perhaps there is an easy, minor bugfix for this that would be
>> palette-able.
>
>
> I've been "afraid" of the hush code for a while. I don't think I want to
> mess with it now. I'll just continue to work with what we've got, carefully.
>
> Thanks again for your attention,
No problem...
Cheers,
-Joe
^ permalink raw reply [flat|nested] 8+ messages in thread
* [U-Boot] HUSH logical AND/OR expressions
2015-04-28 19:47 ` Joe Hershberger
@ 2015-04-28 22:51 ` Wolfgang Denk
2015-04-29 15:19 ` James Chargin
0 siblings, 1 reply; 8+ messages in thread
From: Wolfgang Denk @ 2015-04-28 22:51 UTC (permalink / raw)
To: u-boot
Dear Joe,
In message <CANr=Z=YxsT-VOje5jA0k00BSxNROXBOPXMG-Q_8_7jAYN=fJCw@mail.gmail.com> you wrote:
>
> > I noticed you asked for a reference to the original hush code that is the
> > origin for U-Boot's adaptation. I couldn't find a reply to that question. I
> > also haven't been able to find anything with a quick we search. Do you know
> > where it did come from?
>
> I never got a response, but it appears to be busybox...
Oops, sorry. Yes, of course it is busybox.
As far as I can tell, it was added around October 2001 to the PPCBoot
project as part of the PPCBoot v1.1.0 release:
* Added "hush" shell (from Busybox) as alternative command line
interpreter, thus enabling powerful command line syntax like
if...then...else...fi conditionals or `&&' and '||' constructs
("shell scripts").
See the README file for information about implementation and usage.
Best regards,
Wolfgang Denk
--
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
Winners never talk about glorious victories. That's because they're
the ones who see what the battlefield looks like afterwards. It's
only the losers who have glorious victories.
- Terry Pratchett, _Small Gods_
^ permalink raw reply [flat|nested] 8+ messages in thread
* [U-Boot] HUSH logical AND/OR expressions
2015-04-28 22:51 ` Wolfgang Denk
@ 2015-04-29 15:19 ` James Chargin
0 siblings, 0 replies; 8+ messages in thread
From: James Chargin @ 2015-04-29 15:19 UTC (permalink / raw)
To: u-boot
Wolfgang,
Thanks for your contributions.
On 04/28/2015 03:51 PM, Wolfgang Denk wrote:
> Dear Joe,
>
> In message <CANr=Z=YxsT-VOje5jA0k00BSxNROXBOPXMG-Q_8_7jAYN=fJCw@mail.gmail.com> you wrote:
>>
>>> I noticed you asked for a reference to the original hush code that is the
>>> origin for U-Boot's adaptation. I couldn't find a reply to that question. I
>>> also haven't been able to find anything with a quick we search. Do you know
>>> where it did come from?
>>
>> I never got a response, but it appears to be busybox...
>
> Oops, sorry. Yes, of course it is busybox.
>
> As far as I can tell, it was added around October 2001 to the PPCBoot
> project as part of the PPCBoot v1.1.0 release:
>
> * Added "hush" shell (from Busybox) as alternative command line
> interpreter, thus enabling powerful command line syntax like
> if...then...else...fi conditionals or `&&' and '||' constructs
> ("shell scripts").
>
> See the README file for information about implementation and usage.
>
I should have thought of this myself. I could have looked in the commit
history or release notes.
Just for completeness, I tried the commands using busybox:
# busybox|head -1
BusyBox v1.20.2 (2013-07-02 15:49:59 PDT) multi-call binary.
# false && true || echo ECHO
ECHO
# false && false || echo ECHO
ECHO
# true && false || echo ECHO
ECHO
#
--
Jim Chargin
AJA Video Systems jimc at aja.com
(530) 271-3334 http://www.aja.com
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2015-04-29 15:19 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-04-27 13:39 [U-Boot] HUSH logical AND/OR expressions Joakim Tjernlund
2015-04-28 18:00 ` Joe Hershberger
2015-04-28 18:19 ` James Chargin
2015-04-28 18:35 ` Joe Hershberger
2015-04-28 19:13 ` James Chargin
2015-04-28 19:47 ` Joe Hershberger
2015-04-28 22:51 ` Wolfgang Denk
2015-04-29 15:19 ` James Chargin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox