[OE-core] shell script guidelines in oe-core? (was Re: [PATCH v4] create-pull-request: cleanup bashisms)

Mikko.Rapeli at bmw.de Mikko.Rapeli at bmw.de
Wed Aug 12 09:49:50 UTC 2015


Sorry to hijack the thread but...

On Wed, Aug 12, 2015 at 12:33:31PM +0300, Ed Bartosh wrote:
> Made create-pull-request POSIX compatible:
>    - Replaced /bin/bash -> /bin/sh in shebang.
>    - Replaced usage of pushd/popd with generic shell commands.
>    - Tested on zsh and dash.

This reminded me of the problems I've seen with various oe-core shell scripts:
they are missing systematic error handling.

IMO using bash and 'set -euxo pipefail' are a good approach to catch errors
early in shell scripts. Manually checking for $? is error prone and things
like pipes can hide them. Using undefined variables is another thing
which should fail early before things go horribly wrong. And in build automation
I'd rather see output of -x since things can fail in mysterious ways.
And then there's quoting....

One useful guide is to use shellcheck as static analysis tool for shell scripts.

I guess internally bitbake uses at least set -e.

Comments?

-Mikko


More information about the Openembedded-core mailing list