I am trying to use a user-defined global variable in a
cat <<eof>> filename situation, but it's not working. I found what I want in simple
cat << eof examples on this forum, which led me here: http://www.tldp.org/LDP/abs/html/here-docs.html. But I would like to to something like the following, with the added
filename (This does not work.):
#!/bin/bash #after testing I will define this in .bashrc or somewhere? set IP_ADDR = "188.8.131.52" #empty the file in case there is something in it truncate -s 0 sample.conf # open a file and append cat <<EOF >> sample.conf This is my sample config file Server IP = $IP_ADDR this is the last line of my sample config file EOF #print the file to verify cat sample.conf
This produces a null string after
Server IP =
sed would work if I already had the file written except for the missing variable value, but I won't necessarily have the IP address (or whatever) readily available as a literal string.
Also, I might not have the literal string available for use as a command line parameter when I run the script.
$1 does work within the
cat << eof >> filename code block. I proved that. But I won't have immediate access to the value when I start this script...