Bash Scripting - Here Strings

What are here strings?

Here strings are similar to here documents. A here string is used to for input redirection from text or a variable.

The basic syntax of a here string is as follows:

Here String Syntax


COMMAND <<< text 

Here String Example

Here String Example


#!/bin/bash
#
tr a-z A-Z <<< hello

Output from above script


$ ./string1.sh 
HELLO

Here String Example with a Variable

Here String variable Example


#!/bin/bash
#
myvariable="one two three four five six seven"
tr a-z A-Z <<< $myvariable

Output from above script


$ ./string2.sh 
ONE TWO THREE FOUR FIVE SIX SEVEN