All of lore.kernel.org
 help / color / mirror / Atom feed
* bash specific syntax in bbclass files
@ 2013-05-02  0:13 seth bollinger
  2013-05-02  8:07 ` Paul Eggleton
  0 siblings, 1 reply; 7+ messages in thread
From: seth bollinger @ 2013-05-02  0:13 UTC (permalink / raw)
  To: yocto@yoctoproject.org

Hello All,

I recently ran into a problem in 
meta-raspberrypi/classes/sdcard_image-rpi.bbclass

The following was run through my default debian dash shell (I thought I 
switched a while back, but I must have reverted my VM image or 
something...).

   # If SDIMG_ROOTFS_TYPE is a .xz file use xzcat
   if [[ "$SDIMG_ROOTFS_TYPE" == *.xz ]]
   then

The bash specific syntax ([[) failed in dash causing the "else" path to 
be traversed instead of the correct "then" path.  The failure was silent 
and resulted in a blind copy of a compressed rootfs to the sdcard 
image.  Of course this didn't run.  :)

1.  Is there particular shell syntax that class files should stick too?
2.  I couldn't find a wildcard string search in dash.  Can anyone 
suggest a more shell agnostic way to do this?
3.  Is there a way to guarantee we're running in bash if we're using 
bash specific syntax?

My solution was the following, but it's less readable.

if echo "${SDIMG_ROOTFS_TYPE}" | egrep -q "*\.xz"

Thanks,

Seth



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: bash specific syntax in bbclass files
  2013-05-02  0:13 bash specific syntax in bbclass files seth bollinger
@ 2013-05-02  8:07 ` Paul Eggleton
  2013-05-03  6:36   ` Gaurang Shastri
  0 siblings, 1 reply; 7+ messages in thread
From: Paul Eggleton @ 2013-05-02  8:07 UTC (permalink / raw)
  To: seth bollinger; +Cc: yocto

On Wednesday 01 May 2013 19:13:19 seth bollinger wrote:
> I recently ran into a problem in
> meta-raspberrypi/classes/sdcard_image-rpi.bbclass
> 
> The following was run through my default debian dash shell (I thought I
> switched a while back, but I must have reverted my VM image or
> something...).
> 
>    # If SDIMG_ROOTFS_TYPE is a .xz file use xzcat
>    if [[ "$SDIMG_ROOTFS_TYPE" == *.xz ]]
>    then
> 
> The bash specific syntax ([[) failed in dash causing the "else" path to
> be traversed instead of the correct "then" path.  The failure was silent
> and resulted in a blind copy of a compressed rootfs to the sdcard
> image.  Of course this didn't run.  :)
> 
> 1.  Is there particular shell syntax that class files should stick too?

No bashisms should be used, so the above should really be changed.

> 2.  I couldn't find a wildcard string search in dash.  Can anyone
> suggest a more shell agnostic way to do this?

AFAIK grep or awk is the only way.

> 3.  Is there a way to guarantee we're running in bash if we're using
> bash specific syntax?

Not that I'm aware of.

Cheers,
Paul

-- 

Paul Eggleton
Intel Open Source Technology Centre


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: bash specific syntax in bbclass files
  2013-05-02  8:07 ` Paul Eggleton
@ 2013-05-03  6:36   ` Gaurang Shastri
  2013-05-03  6:58     ` Paul Eggleton
  0 siblings, 1 reply; 7+ messages in thread
From: Gaurang Shastri @ 2013-05-03  6:36 UTC (permalink / raw)
  To: Paul Eggleton; +Cc: yocto@yoctoproject.org

[-- Attachment #1: Type: text/plain, Size: 1702 bytes --]

I usually do following before starting Yocto on Ubuntu:
--
# dpkg-reconfigure dash
and select "NO" on the prompt
--

The above will at least make bash as default shell.

//Gaurang Shastri


On Thu, May 2, 2013 at 1:37 PM, Paul Eggleton <paul.eggleton@linux.intel.com
> wrote:

> On Wednesday 01 May 2013 19:13:19 seth bollinger wrote:
> > I recently ran into a problem in
> > meta-raspberrypi/classes/sdcard_image-rpi.bbclass
> >
> > The following was run through my default debian dash shell (I thought I
> > switched a while back, but I must have reverted my VM image or
> > something...).
> >
> >    # If SDIMG_ROOTFS_TYPE is a .xz file use xzcat
> >    if [[ "$SDIMG_ROOTFS_TYPE" == *.xz ]]
> >    then
> >
> > The bash specific syntax ([[) failed in dash causing the "else" path to
> > be traversed instead of the correct "then" path.  The failure was silent
> > and resulted in a blind copy of a compressed rootfs to the sdcard
> > image.  Of course this didn't run.  :)
> >
> > 1.  Is there particular shell syntax that class files should stick too?
>
> No bashisms should be used, so the above should really be changed.
>
> > 2.  I couldn't find a wildcard string search in dash.  Can anyone
> > suggest a more shell agnostic way to do this?
>
> AFAIK grep or awk is the only way.
>
> > 3.  Is there a way to guarantee we're running in bash if we're using
> > bash specific syntax?
>
> Not that I'm aware of.
>
> Cheers,
> Paul
>
> --
>
> Paul Eggleton
> Intel Open Source Technology Centre
> _______________________________________________
> yocto mailing list
> yocto@yoctoproject.org
> https://lists.yoctoproject.org/listinfo/yocto
>

[-- Attachment #2: Type: text/html, Size: 2563 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: bash specific syntax in bbclass files
  2013-05-03  6:36   ` Gaurang Shastri
@ 2013-05-03  6:58     ` Paul Eggleton
  2013-05-03 11:40       ` Trevor Woerner
  0 siblings, 1 reply; 7+ messages in thread
From: Paul Eggleton @ 2013-05-03  6:58 UTC (permalink / raw)
  To: Gaurang Shastri; +Cc: yocto@yoctoproject.org

On Friday 03 May 2013 12:06:45 Gaurang Shastri wrote:
> I usually do following before starting Yocto on Ubuntu:
> --
> # dpkg-reconfigure dash
> and select "NO" on the prompt
> --
> 
> The above will at least make bash as default shell.

Yes, except as I mentioned recently we shouldn't need to be forcing bash and 
we no longer advise users to do this. I am using Ubuntu with the default dash 
shell to build on here, for example.

Cheers,
Paul

-- 

Paul Eggleton
Intel Open Source Technology Centre


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: bash specific syntax in bbclass files
  2013-05-03  6:58     ` Paul Eggleton
@ 2013-05-03 11:40       ` Trevor Woerner
  2013-05-03 12:12         ` Robert P. J. Day
  2013-05-03 12:25         ` Paul Eggleton
  0 siblings, 2 replies; 7+ messages in thread
From: Trevor Woerner @ 2013-05-03 11:40 UTC (permalink / raw)
  To: yocto@yoctoproject.org

If every other distribution, over the next year, switched to python-3
as their default, but (instead of updating) future versions of Ubuntu
installed a symlink called python-3 pointing back to python-2, would
that hold back Yocto from adopting python-3-isms too?

It's sad how Ubuntu has so effectively killed the adoption of all
features of bash (the default shell on many Linux distributions)
introduced in the last 10 years by masquerading their crippled shell
as "bash". And it's even sadder to see how so many projects, in
response, have simply said "let's write all our shell scripts in
original Bourne shell syntax" as a result.



Disclaimer: I didn't write the shell code in question, so please don't
assume I'm "taking this personally". I'm just making a general
observation.


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: bash specific syntax in bbclass files
  2013-05-03 11:40       ` Trevor Woerner
@ 2013-05-03 12:12         ` Robert P. J. Day
  2013-05-03 12:25         ` Paul Eggleton
  1 sibling, 0 replies; 7+ messages in thread
From: Robert P. J. Day @ 2013-05-03 12:12 UTC (permalink / raw)
  To: Trevor Woerner; +Cc: yocto@yoctoproject.org

On Fri, 3 May 2013, Trevor Woerner wrote:

> If every other distribution, over the next year, switched to
> python-3 as their default, but (instead of updating) future versions
> of Ubuntu installed a symlink called python-3 pointing back to
> python-2, would that hold back Yocto from adopting python-3-isms
> too?
>
> It's sad how Ubuntu has so effectively killed the adoption of all
> features of bash (the default shell on many Linux distributions)
> introduced in the last 10 years by masquerading their crippled shell
> as "bash". And it's even sadder to see how so many projects, in
> response, have simply said "let's write all our shell scripts in
> original Bourne shell syntax" as a result.

  personally, i try to be posix-compliant as much as possible to
avoid this kind of grief.

rday

-- 

========================================================================
Robert P. J. Day                                 Ottawa, Ontario, CANADA
                        http://crashcourse.ca

Twitter:                                       http://twitter.com/rpjday
LinkedIn:                               http://ca.linkedin.com/in/rpjday
========================================================================


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: bash specific syntax in bbclass files
  2013-05-03 11:40       ` Trevor Woerner
  2013-05-03 12:12         ` Robert P. J. Day
@ 2013-05-03 12:25         ` Paul Eggleton
  1 sibling, 0 replies; 7+ messages in thread
From: Paul Eggleton @ 2013-05-03 12:25 UTC (permalink / raw)
  To: Trevor Woerner; +Cc: yocto

On Friday 03 May 2013 07:40:24 Trevor Woerner wrote:
> If every other distribution, over the next year, switched to python-3
> as their default, but (instead of updating) future versions of Ubuntu
> installed a symlink called python-3 pointing back to python-2, would
> that hold back Yocto from adopting python-3-isms too?

That's not quite the same situation and I don't think they would do that. They 
might however (as I guess they do now) point the standard python binary at 
python2 and then expect those using python3 scripts to explicitly request 
python3.

> It's sad how Ubuntu has so effectively killed the adoption of all
> features of bash (the default shell on many Linux distributions)
> introduced in the last 10 years by masquerading their crippled shell
> as "bash". And it's even sadder to see how so many projects, in
> response, have simply said "let's write all our shell scripts in
> original Bourne shell syntax" as a result.

Well, that is one way of looking at it; the change to dash in Ubuntu has 
indeed been quite a painful road (not so much for us but for the Linux 
ecosystem in general). On the other hand, it's not that dash is masquerading 
as bash, it's selected as providing /bin/sh. If you have written a shell 
script that starts with #!/bin/sh and then proceeds to use bash-specific 
syntax, sure it might well work on most systems because they're using bash, 
but the script started with something that wasn't true - it's not in fact a 
standard Unix Bourne-compatible shell script, it's a bash script.

It's also worth mentioning that we have had some benefit out of these changes, 
in that the scripts that have been fixed that end up running on the target will 
now more likely run when /bin/sh is provided by ash (i.e. busybox).

Cheers,
Paul

-- 

Paul Eggleton
Intel Open Source Technology Centre


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2013-05-03 12:25 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-05-02  0:13 bash specific syntax in bbclass files seth bollinger
2013-05-02  8:07 ` Paul Eggleton
2013-05-03  6:36   ` Gaurang Shastri
2013-05-03  6:58     ` Paul Eggleton
2013-05-03 11:40       ` Trevor Woerner
2013-05-03 12:12         ` Robert P. J. Day
2013-05-03 12:25         ` Paul Eggleton

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.