On Thu, Jan 08, 2004 at 11:59:20PM -0500, Post, Mark K wrote:
> Ok, this is going to require some level of bash expertise, just to warn
> everyone. I have a script that writes data to a file. One version of it
> works, the other does not. By "works," I mean that a symbolic substitution
> is performed. In detail, if I do this:
> #!/bin/sh
> VERSION=3.3
> cat > doinst.sh << EOF
> ( cd usr/bin ; ln -sf gcc-$VERSION gcc )
> ( cd usr/bin ; rm -rf s390-slackware-linux-gcc-$VERSION )
> ( cd usr/bin ; ln -sf gcc-$VERSION s390-slackware-linux-gcc-$VERSION )
> EOF
>
> When the output file, doinst.sh, is examined, the $VERSION variables have
> been properly substituted with the value 3.3. When I do this:
> #!/bin/sh
> VERSION=3.3
> cat > doinst1.sh << "EOF"
> ( cd usr/bin ; ln -sf gcc-$VERSION gcc )
> ( cd usr/bin ; rm -rf s390-slackware-linux-gcc-$VERSION )
> ( cd usr/bin ; ln -sf gcc-$VERSION s390-slackware-linux-gcc-$VERSION )
> EOF
>
> When the output file is examined, the $VERSION variables appear just like
> that, as $VERSION, and not as 3.3.
>
> So, can someone explain to me why this works the way it does? Pointing to
> the relevant passage(s) in the Bash man page should be sufficient. If that
> doesn't clear it up for me, I'll ask more questions later.
Here Documents
This type of redirection instructs the shell to read input
from the current source until a line containing only word
(with no trailing blanks) is seen. All of the lines read
up to that point are then used as the standard input for a
command.
The format of here-documents is as follows:
<<[-]word
here-document
delimiter
No parameter expansion, command substitution, arithmetic
expansion, or pathname expansion is performed on word. If
>> any characters in word are quoted, the delimiter is the
>> result of quote removal on word, and the lines in the
>> here-document are not expanded. If word is unquoted, all
lines of the here-document are subjected to parameter
expansion, command substitution, and arithmetic expansion.
In the latter case, the character sequence \<newline> is
ignored, and \ must be used to quote the characters \, $,
and `.
If the redirection operator is <<-, then all leading tab
characters are stripped from input lines and the line con-
taining delimiter. This allows here-documents within
shell scripts to be indented in a natural fashion.
Richard