Hi,
I've got something I cannot explain maybe there's somebody out there who
can.
I simplified the problem to make it more clear. First of all some basics.
The $(...) structure can be used to do command substitution.
The `...` structure does the same thing.
example :
echo $(echo "1:2:3"|cut -d: -f2) -> 2
echo `echo "1:2:3"|cut -d: -f2` -> 2
the << structure can be used to replace standard input for a command with
fixed input
example
cat <<EOF
hello mister
EOF
result
hello mister
The best way to understand this is to see the input between the both EOF's
as being input in a input file and the file is being shown by cat.
So,
file a.txt contains
hello mister
cat a.txt -> hello mister
The strength of this construction is the fact it can be used in combination
with variables
var1=mister
cat <<EOF
hello ${var1}
EOF
result
hello mister
If I combine this with the command substitution I can do
var1=mister
var2=$(cat <<EOF
hello ${var1}
EOF)
var2 contains now: hello mister
I also can use single quotes around the variable
var1=mister
cat <<EOF
hello '${var1}'
EOF
result
hello 'mister'
NOW IT COMES
if I want to put this in var2 using command substitution I use
var1=mister
var2=$( cat <<EOF
hello '${var1}'
EOF)
var2 now contains !!!!!!!!!! -> hello "${var1}"
Note the single quotes are converted into double quotes and the variable is
not expanded.
NOT IT COMES BIGTIME
If I use the other construction to do command substitution I get the
following
var1=mister
var2=` cat <<EOF
hello '${var1}'
EOF`
var2 now contains -> hello 'mister'
This is what I expected the first time
The <<EOF construction doesn't do the conversion as shown above, so I would
conclude that the $(...) construction does this conversion.
NOW IT COMES AGAIN
If I do this:
var1=mister
var2=$(echo "hello '${var1}')
var2 now contains -> hello 'mister'
So here I would conclude $(...) doesn't do the conversion either. DUHH!??!?
So it looks like there is some relationship between the combination $(...)
and the <<EOF construction
WHO CAN HELP????