[PATCH] gen_build_files.sh: Remove bashisms
Denys Vlasenko
vda.linux at googlemail.com
Sat May 15 19:05:19 UTC 2010
On Friday 14 May 2010 22:52, Peter Tyser wrote:
> On Fri, 2010-05-14 at 15:41 -0500, Rob Landley wrote:
> > On Thursday 13 May 2010 18:05:53 Peter Tyser wrote:
> > > Using 'read' without a variable is not supported in many shells. Lines
> > > such as 'while read; do' in gen_build_files.sh would result in build
> > > failures when using sh or dash as an interpreter:
> >
> > Simple fix: say #!/bin/bash at the top of all shell scripts, always.
>
> With the exception of fix_ws.sh, all other shell scripts in scripts/
> use /bin/sh. I had assumed this was intentional? Unless there is a
> specific bashism that makes gen_build_files.sh much cleaner/better/etc,
"read -r" without argument does not strip leading whitespace from the read line.
"read -r REPLY" does.
This can be fought with with IFS tricks, which looks ugly (what if you
need to restore IFS? brrr):
$ (echo " a \ b " | { read -r; echo "[$REPLY]"; })
[ a \ b ]
$ (echo " a \ b " | { read -r REPLY; echo "[$REPLY]"; })
[a \ b]
$ (IFS=''; echo " a \ b " | { read -r REPLY; echo "[$REPLY]"; })
[ a \ b ]
> why not keep it portable? I also personally prefer explicitly
> specifying a variable for 'read' instead of using the "magical" REPLY
> variable.
--
vda
More information about the busybox
mailing list