Quote:
Originally Posted by Dimitriy
jschiwal: I kinda see what you are saying but I am not fully grasping the idea. The sed inserting i/a commands for the JAVA path makes sense.
But the sourcing template part I do not fully understand.
installer.sh (focusing on the variables for the moment)
Code:
...
cat >subsonic.sh <<- EOF
#!/bin/sh
JAVA_HOME=$JAVA_HOME
SUBSONIC_HOME=$SUBSONIC_HOME
SUBSONIC_PORT=$SUBSONIC_PORT
SUBSONIC_DEFAULT_MUSIC_FOLDER=$SUBSONIC_DEFAULT_MUSIC_FOLDER
EOF
Vairables expanding first makes sense. What I can't seem to understand is what the cat command is doing.
thank you,
d
|
Cat is simply writing to the file. It prints out the contents of the file,
or of stdin if there is no file argument. So in this case, it is printing the contents of STDIN, which is coming from the HERE document.
Instead of cat'ing a template file, you are cat'ing the contents of the HERE document, and writing the contents to a file
after the variables are evaluated.
It may be that you didn't realize that cat would print the contents of stdin. The << redirects the contents of the rest of the file up to the terminator to stdin, so that is what `cat' reads and prints. The redirection operator writes to a file instead of stdio.
So the stream goes from installscript --> `<<' --> stdio --> cat --> stdout --> file.
Also look at the form of variable evaluation: ${variable:=default}
This allow you to give the variable a default value. If it doesn't have a value, the variable evaluates to the default.
Another advantage to using HERE documents is that you can have more than one in your script. The same script could create and edit a number of config files.