Re: bash shell script questions
David Stern wrote:
[snip]
> > You should use '#!/bin/bash' really, because now sh is just a link
> > to bash, but you are not guaranteed that in a future version it will
> > be another shell, or that bash _will_ act more (dumb) Bourne like in
> > the future when called as 'sh' (I for one would appreciate it).
>
> Noted. However I thought that /bin/sh was more "un*x-compatible", thus
> more extensible across other platforms where bash may not be available,
> therefore making /bin/sh preferred. True?/Not true?
>
> (When, if ever, do you think use of /bin/sh is appropriate?)
You should use hashpling with /bin/sh if you are sure that your script
is _bourne_ compatible. echo -e is not. Another example I stumbled upon
is that redirection and piping in a bourne shell is done within a subshell.
Any posix shell (bash, ksh) will do it in the current shell. So something
like:
while read VAR ; do
eval ARR${COUNT}=${VAR}
COUNT=`expr $COUNT + 1`
done < foo
echo $ARR1
will assign a value to ARR1, ARR2 etc out of the file foo, when using
a posix shell. Bourne will not keep the value, because the assignment
is done in a subshell.
If you do not have any of those diffs in your script, use #!/bin/sh,
else use #!/bin/bash. (MHO)
HTH,
Rob.
--
Rob S. Wolfram rsw@mcs.nl rwolfram@wi.leidenuniv.nl
W3: http://www.mcs.nl/~rsw http://www.wi.leidenuniv.nl/~rwolfram
PGP: 768/07606049 31 09 D2 D7 57 B4 F4 FC CA FC 1F 34 8C BA C8 56
--
TO UNSUBSCRIBE FROM THIS MAILING LIST: e-mail the word "unsubscribe" to
debian-user-request@lists.debian.org .
Trouble? e-mail to templin@bucknell.edu .
Reply to: