Re: [U-Boot] HUSH logical AND/OR expressions

2015-04-29 Thread James Chargin

Wolfgang,

Thanks for your contributions.

On 04/28/2015 03:51 PM, Wolfgang Denk wrote:

Dear Joe,

In message  
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   j...@aja.com
(530) 271-3334  http://www.aja.com
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


Re: [U-Boot] HUSH logical AND/OR expressions

2015-04-28 Thread Wolfgang Denk
Dear Joe,

In message  
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: w...@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_
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


Re: [U-Boot] HUSH logical AND/OR expressions

2015-04-28 Thread Joe Hershberger
Hi James,

On Tue, Apr 28, 2015 at 2:13 PM, James Chargin  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 
>> 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
  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
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


Re: [U-Boot] HUSH logical AND/OR expressions

2015-04-28 Thread James Chargin

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  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
 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

___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


Re: [U-Boot] HUSH logical AND/OR expressions

2015-04-28 Thread Joe Hershberger
Hi James,

On Tue, Apr 28, 2015 at 1:19 PM, James Chargin  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
>>  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
> 
>
> 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
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


Re: [U-Boot] HUSH logical AND/OR expressions

2015-04-28 Thread James Chargin

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
 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 



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   j...@aja.com
(530) 271-3334  http://www.aja.com
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


Re: [U-Boot] HUSH logical AND/OR expressions

2015-04-28 Thread Joe Hershberger
Hi Joakim,

On Mon, Apr 27, 2015 at 8:39 AM, Joakim Tjernlund
 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
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


[U-Boot] HUSH logical AND/OR expressions

2015-04-27 Thread Joakim Tjernlund
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
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot