Beware of bash 3.1

Stephen John Smoogen smooge at gmail.com
Sat Apr 29 04:07:44 UTC 2006


On 4/28/06, Callum Lerwick <seg at haxxed.com> wrote:
> Okay, I originally posted about this a few months ago:
>
> http://www.redhat.com/archives/rhl-devel-list/2006-January/msg00491.html
>
> A seemingly harmless corner case. Here's another one:
>
> <BobJensen> one of my guys ran a java install script as sudo and fubar'd
> the box
> <BobJensen> he was following these instructions
> http://fedorasolved.org/browser-solutions/java-i386/
>
> Step 9, which looks like this:
>
> cat <<EOF > /etc/profile.d/java.sh
> export JAVA_HOME=/opt/jre1.5.0_06
> export PATH=$JAVA_HOME/bin:$PATH
> EOF
>
> Results in this:
>
> # cat /etc/profile.d/java.sh
> export JAVA_HOME=/opt/jre1.5.0_06
> export PATH=/bin:/usr/kerberos/sbin:/usr/kerberos/bin:/usr/lib64/ccache:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
>
> Which is wrong. The fix is of course:
>
> # cat <<EOF > ~/java.sh
> > export JAVA_HOME=/opt/jre1.5.0_06
> > export PATH=\$JAVA_HOME/bin:\$PATH
> > EOF
>
> # cat ~/java.sh
> export JAVA_HOME=/opt/jre1.5.0_06
> export PATH=$JAVA_HOME/bin:$PATH
>
> So... bash 3.1 has definitely changed the way variable expansion is
> done, namely it expands things it didn't used to expand. Bug or feature?
> Either way, beware.
>

In my bash addled brain.. I would say it is a bug. Expanding out data
that is being done in an EOF does not look in any way sh/ksh/etc
compliant.. and just prone to breaking too many things.




--
Stephen J Smoogen.
CSIRT/Linux System Administrator




More information about the devel mailing list