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.
(And there's the larger issue, being that those instructions suck, instead you should be using http://www.city-fan.org/tips/JpackageJava which is linked from http://www.fedoraproject.org/wiki/JavaFAQ and thus appears to be officially blessed. But that's not really an issue for -devel...)
Okay, I was dumb and didn't actually test on bash 3.0. No more FC4 boxes around. And my debian box is up to 3.1 now as well. Here's my gentoo embedded chroot:
burgertime / # bash --version GNU bash, version 3.00.16(1)-release (i586-gentoo-linux-uclibc) Copyright (C) 2004 Free Software Foundation, Inc. burgertime / # cat <<EOF > asfasdfasd
export JAVA_HOME=/opt/jre1.5.0_06 export PATH=$JAVA_HOME/bin:$PATH EOF
burgertime / # cat asfasdfasd export JAVA_HOME=/opt/jre1.5.0_06 export PATH=/bin:/usr/kerberos/bin:/usr/lib64/ccache:/usr/local/bin:/usr/bin:/bin:/usr/X11R6/bin:/home/seg/bin
And going back to my original bug:
burgertime ~ # echo ${PWD/#$HOME/~} ~ burgertime ~ # echo ~ /home/seg
And under FC5:
$ echo ${PWD/#$HOME/~} /home/seg $ echo ~ /home/seg
So now I'm confused and embarrassed, and those instructions are broken on FC4 as well.
On 4/28/06, Callum Lerwick seg@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
On 4/28/06, Stephen John Smoogen smooge@gmail.com wrote:
cat <<EOF > /etc/profile.d/java.sh export JAVA_HOME=/opt/jre1.5.0_06 export PATH=$JAVA_HOME/bin:$PATH EOF
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.
Ok definately need sleep. It is doing what it is supposed to do in EOF sections. I am going to bed.. nevermind
-- Stephen J Smoogen. CSIRT/Linux System Administrator
Stephen John Smoogen wrote :
On 4/28/06, Stephen John Smoogen smooge@gmail.com wrote:
cat <<EOF > /etc/profile.d/java.sh export JAVA_HOME=/opt/jre1.5.0_06 export PATH=$JAVA_HOME/bin:$PATH EOF
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.
Ok definately need sleep. It is doing what it is supposed to do in EOF sections. I am going to bed.. nevermind
Yeah, isn't the proper fix to simply single quote 'EOF'? Like this :
cat << 'EOF' > /etc/profile.d/java.sh export JAVA_HOME=/opt/jre1.5.0_06 export PATH=$JAVA_HOME/bin:$PATH EOF
This should keep the $VARIABLES from being expanded in the resulting file.
Matthias
On 4/29/06, Matthias Saou thias@spam.spam.spam.spam.spam.spam.spam.egg.and.spam.freshrpms.net wrote:
Stephen John Smoogen wrote :
On 4/28/06, Stephen John Smoogen smooge@gmail.com wrote:
cat <<EOF > /etc/profile.d/java.sh export JAVA_HOME=/opt/jre1.5.0_06 export PATH=$JAVA_HOME/bin:$PATH EOF
Yeah, isn't the proper fix to simply single quote 'EOF'? Like this :
cat << 'EOF' > /etc/profile.d/java.sh export JAVA_HOME=/opt/jre1.5.0_06 export PATH=$JAVA_HOME/bin:$PATH EOF
This should keep the $VARIABLES from being expanded in the resulting file.
Yes I think it is. I prefer to stay away from EOF data's because of forgetting one thing or another can cause weird thing to happen. I think I have used it more in Perl (and maybe Awk) than I have in Bash/Ksh
-- Stephen J Smoogen. CSIRT/Linux System Administrator
On Fri, 2006-04-28 at 22:07 -0600, Stephen John Smoogen wrote:
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.
Yeah I now realize I've hit this before, with people putting config files inside specs instead of sourcing them. Icky. Several layers of variable/macro expansion is fun... (NOTABUG in bash 3.1 after all...)
Once upon a time, Callum Lerwick seg@haxxed.com said:
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
<snip>
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.
Nope, nope, and nope. base 3.1 hasn't changed that, it isn't a bug, nor a "feature". It is the standard documented behavior and I believe the behavior all the way back to the beginning of the Bourne shell.
The only bug is in poor (and apparently untested) instructions.
devel@lists.stg.fedoraproject.org