17.1. Here Strings
A here string can be considered as
a stripped-down form of here document. It
consists of nothing more than COMMAND
<<<$WORD, where $WORD
is expanded and fed to the stdin of
Example 17-13. Prepending a line to a file
# prepend.sh: Add text at beginning of file.
# Example contributed by Kenny Stauffer,
#+ and slightly modified by document author.
read -p "File: " file # -p arg to 'read' displays prompt.
if [ ! -e "$file" ]
then # Bail out if no such file.
echo "File $file not found."
read -p "Title: " title
cat - $file <<<$title > $file.new
echo "Modified file is $file.new"
# from 'man bash':
# Here Strings
# A variant of here documents, the format is:
# The word is expanded and supplied to the command on its standard input.
Exercise: Find other uses for here