The here string and the <<< operator

The here string is used for input redirection from <indexentry content="<<text or a variable. Input is mentioned on the same line within single quotes ('').

The syntax is as follows:

    $ command <<< 'string'
  
  1. Let's see the following example, hereString_01.sh:
#!/bin/bash 
wc -w <<< 'Good Morning and have a nice day !' 
  1. Save the file, give the permission, and run the script as follows:
    $ chmod u+x hereString_01.sh
    $ ./hereString_01.sh
  
  1. Here is the output:
    8
  

In this example, the string Good Morning and have a nice day ! is called as the here string.

Get Learning Linux Shell Scripting - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.