Skip to contentSkip to conversation

bash specific syntax in bbclass files

DISCUSSION seth bollinger 5 participants 7 messages May 2, 2013 – May 3, 2013

lore
Share & tools
lore
#0 lore raw

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

#1 lore raw
Quoted 11 lines · 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

Quoted 6 lines

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.

Quoted 2 lines

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.

Quoted 2 lines

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

Signature · 2 lines
Paul Eggleton
Intel Open Source Technology Centre
#2 lore raw

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 <[email protected]

Quoted 45 lines

wrote:

Quoted 11 lines · 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

Quoted 6 lines

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.

Quoted 2 lines

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.

Quoted 2 lines

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
[email protected]
https://lists.yoctoproject.org/listinfo/yocto

#3 lore raw
Quoted 7 lines · 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

Signature · 2 lines
Paul Eggleton
Intel Open Source Technology Centre
#4 lore raw

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.

#5 lore raw
Quoted 6 lines · Trevor Woerner

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?

Quoted 6 lines

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

Signature · 7 lines
========================================================================
Robert P. J. Day                                 Ottawa, Ontario, CANADA
                        http://crashcourse.ca

Twitter:                                       http://twitter.com/rpjday
LinkedIn:                               http://ca.linkedin.com/in/rpjday
========================================================================
#6 lore raw
In reply to Trevor Woerner
Quoted 4 lines · 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.

Quoted 6 lines

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

Signature · 2 lines
Paul Eggleton
Intel Open Source Technology Centre