[TriLUG] HERE document question
Joseph Mack NA3T
jmack at wm7d.net
Sun Jul 25 19:16:00 EDT 2010
Here's my script
#!/bin/bash
.
.
partition=/dev/sda1
cat > restore.sh << EOF
count=`df | grep -c $partition`
EOF
# ----end script
if $partition is not mounted at the time the generating
script is run, then the output is
count=0
I want the HERE document to be
count=`df | grep -c /dev/sda1`
so that the mount state is determined at the time the HERE
document is run, not at the time the HERE document is
generated. (There HERE document has other variables whose
value should be substituted at the time the file is
generated.)
if instead I stop substitution by using the construct
cat > restore.sh <<\EOF
count=`df | grep -c $partition`
EOF
the HERE document then is the literal line above
count=`df | grep -c $partition`
which requires me to get the value of $partition into the
HERE document somehow.
I've tried a few other variations eg
command="df | grep -c $partition"
count=`eval $command`
where `eval $command` comes out null in the HERE document
Any ideas?
Thanks Joe
--
Joseph Mack NA3T EME(B,D), FM05lw North Carolina
jmack (at) wm7d (dot) net - azimuthal equidistant map
generator at http://www.wm7d.net/azproj.shtml
Homepage http://www.austintek.com/ It's GNU/Linux!
More information about the TriLUG
mailing list