Creating files with some content with shell script Creating files with some content with shell script unix unix

Creating files with some content with shell script


You can use a here document:

cat <<EOF >/home/a.configfirst linesecond linethird lineEOF

You can place several of these in the same script.

On OS-X the command should be:

cat > filename <<- "EOF"file contentsmore contentsEOF


file="/tmp/test.txt"echo "Adding first line" > $fileecho "Adding first line replaced" > $fileecho "Appending second line " >> $fileecho "Appending third line" >> $filecat $file

> to add/replace the content ( here actual content got replaced by the 2nd line)
>> to append

Result
Adding first line replaced
Appending second line
Appending third line


Like so:

#!/bin/bashvar="your text"echo "simply put,just so: $var" > a.config

For further info, see Input/Output part of abs.
Hope, this helps.