Using echo to create a script

Hello all,

I want to be able to create a script on the fly from another script by echoing lines into a file, but am running into difficulty, as it isn't working right. What am I doing wrong?

echo "for i in `grep $FRAME /root_home/powermt.sort.fil |awk '{print $7}'`" > pvtimout_set.sh
echo "do" >> pvtimout_set.sh
echo "echo ${i} ----------" >> pvtimout_set.sh
echo "echo pvchange -t 90 /dev/dsk/${i}" >> pvtimout_set.sh
echo "pvchange -t 90 /dev/dsk/${i}" >> pvtimout_set.sh
echo >> pvtimout_set.sh
echo "echo pvdisplay /dev/dsk/${i} |grep Timeout" >> pvtimout_set.sh
echo "pvdisplay /dev/dsk/${i} |grep Timeout" >> pvtimout_set.sh
echo >> pvtimout_set.sh
echo "done 2> /root_home/scripts/pvtimout.out 1>&2" >> pvtimout_set.sh

Thanks for any help in advance!

Escape those accent graves with a backslash character each.

tyler_durden

The problem is caused by not escaping characters which will be interpreted by the shell (e.g. dollar and backtick ... and maybe more) where you want them to appear in the new script. It might be easier to write the script in the normal manner and call it with a parameter.

If you persist with this approach, test thoroughly before executing the new script.

The lines starting ... echo "echo ... need attention to stop the pipe becoming active in the new script because the echoed string will not be in quotes.

Thanks! Here is what I did, based on some help I received:

cat <<-EOF! > pvtimeout_set.sh
for i in \`grep ${FRAME} /tmp/powermt.sort.out |awk '{print \$7}'\`
do
echo \${i} ----------
echo pvchange -t 90 /dev/dsk/\${i}
pvchange -t 90 /dev/dsk/\${i}
echo pvdisplay /dev/dsk/\${i} |grep Timeout
pvdisplay /dev/dsk/\${i} |grep Timeout
echo
done
EOF!

FYI:

     << [-]word
           The shell input is read up to a line that is the  same
           as word, or to an EOF. No parameter substitution, com-
           mand substitution, or file  name  generation  is  per-
           formed  on  word.  The  resulting  document,  called a
           here-document, becomes  the  standard  input.  If  any
           character  of  word  is  quoted,  no interpretation is
           placed upon the characters of the document. Otherwise,
           parameter  and command substitution occur, \NEWLINE is
           ignored, and \ must be used to quote the characters \,
           $,  `,  and  the  first  character  of  word.  If - is
           appended to <<, then all  leading  tabs  are  stripped
           from word and from the document.

Thanks.