[GRASS-dev] [bug #5499] (grass) bash scripts starting with
#!/bin/sh
Hamish
hamish_nospam at yahoo.com
Tue Feb 20 20:14:18 EST 2007
Glynn Clements wrote:
[r.in.wms/wms.request]
> Arrays are a bash extension.
>
> AFAICT, the array is never actually used, so removing that line should
> be harmless.
done in CVS, along with some other cleanups. r.in.wms still needs a lot
more error checking built into it*, but is now free of bashisms.
[*] it now exits gracefully if r.tileset (by way of wms.request) failed.
[r.tileset]
> > Setting it back to /bin/bash solved the problem, but still
> > indicating the right interpreter in the headers will also be great.
Glynn:
> The problem is that you can't rely upon bash being installed in a
> specific location[1]. On Linux, it's the "primary" shell, so it's
> /bin. On Unices which include it as an "extra", it's likely to be in
> /usr/bin. If it isn't part of the core OS, it could be anywhere,
> although /usr/local/bin, /sw/bin and /opt/sw/bin are all plausible.
>
> [1] Actually, you can't rely upon bash being installed at all. GRASS
> isn't specifically a Linux package; at least, it isn't supposed to be.
>
> The only thing which you can absolutely rely upon is that /bin/sh will
> be a POSIX-compatible Bourne shell. Anyone writing scripts would do
> well to bear this in mind (IOW, please avoid using bash-specific
> features).
I don't think it is practical for r.tileset to be free of Bash without
a complete rewrite. It's really a Bash program and not a shell script.
If it were to be rewritten, perhaps do it in python, but as bash will
be more widely installed than python I see little point in doing that.
Python (or perl) will have the same "where'd it get installed?"
problems too, probably more so. r.tileset is more complicated than you
really want a shell script to be, but isn't so deep that it should be
written in C either. Somewhere in between.
Options I can think of:
1) change the r.tileset shebang to #!/bin/bash. Let the packagers of
platforms that don't supply bash in the normal place worry about
modifying the script + Make a note in the r.tileset help page.
At least there will be a useful help message and graceful exit if the
path is wrong.
2) keep #!/bin/sh, but add this within the script:
if [ -z "$BASH" ] ; then
echo "$0: This script requires Bash." 1>&2
exit 1
fi
3) Rewrite it in a language other than Bash.
#1 seems the most correct. #2 seems the most practical, but dirty.
Can we name any popular modern platform which doesn't keep bash in
/bin/bash?
Hamish
More information about the grass-dev
mailing list