Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Mail Systems
Eclipse Documentation

How To Guides
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Problem Solutions
Privacy Policy




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 COMMAND.

Example 17-13. Prepending a line to a file

# 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 > $

echo "Modified file is $"

exit 0

# from 'man bash':
# Here Strings
# 	A variant of here documents, the format is:
# 		<<<word
# 	The word is expanded and supplied to the command on its standard input.

Exercise: Find other uses for here strings.

  Published under the terms of the GNU General Public License Design by Interspire