Underscore “_” is *sometimes* a metacharacter in the Bourne shell, and \ doesn’t protect it, but ” does!


Hahaha. Jokes on me.
Read ’em and weep:
———————————————————–
$!sh
export FOO=2
export BAR=5
touch java.hprof.txt

cp java.hprof.txt “a$FOO_$BAR.txt” produces: a5.txt
cp java.hprof.txt “a$BAR_$FOO.txt” produces: a2 .txt
cp java.hprof.txt “aBackSlash\_$FOO\_$BAR.txt” produces: aBackSlash\_2\_5.txt
cp java.hprof.txt “a_$BAR_$FOO.txt” produces: a_2.txt
cp java.hprof.txt aIndiQuoted”_”$FOO”_”$BAR.txt produces: aIndiQuoted_2_5.txt
cp java.hprof.txt “aNoDash$FOO$BAR.txt” produces: aNoDash25.txt
cp java.hprof.txt “adot.$FOO.$BAR.txt” produces: adot.2.5.txt
cp java.hprof.txt “aquoted_$FOO_$BAR.txt” produces: aquoted_5.txt

Oh for crying out loud!

Well, ok, you have to quote the underbars to get them through, at least its possible, but what can possibly justify:
export FOO=2
export BAR=5
cp java.hprof.txt “a_$BAR_$FOO.txt” produces: a_2.txt
cp java.hprof.txt “a$BAR_$FOO.txt” produces: a2 .txt

its $FOO that’s getting through, but the underbar BEFORE it doesn’t!!! Its the underbar before $BAR that gets through. That’s messed up, IHMO.

Dykstra probably has a foot note explaning why this is what I should expect. Bleh.

RIght, then.

Bill

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s