8.18 Here Documents
So far, we've talked about three different kinds of quoting:
backslashes (
sort >file <<EndOfSort zygote abacus EndOfSort This is very useful because variables ( 6.8 , 6.1 ) are evaluated during this operation. Here is a way to transfer a file using anonymous ftp ( 52.7 ) from a shell script:
#!/bin/sh # Usage: # ftpfile machine file # set -x SOURCE=$1 FILE=$2 GETHOST="uname -n" BFILE=`basename $FILE` ftp -n $SOURCE <<EndFTP ascii user anonymous $USER@`$GETHOST` get $FILE /tmp/$BFILE EndFTP As you can see, variables and command substitutions ( 9.16 ) are done. If you don't want those to be done, put a backslash in front of the name of the word:
cat >file <<\FunkyStriNG
Notice the funky string. This is done because
it is very unlikely that I will want to put that particular
combination of
characters in any file.
You should be warned that the C shell expects the
matching word (at the end of the list) to be escaped the same way, i.e.,
[Most Bourne shells also have the - |
|