Bonus: Redirect STDIN

Redirect STDIN

So far you have given bash commands input in two ways:

  1. as command arguments
  2. via converting STDOUT from a preceding command into STDIN using the pipe operator

These are the two ways you should expect to work with STDIN in this course.

However, there are additional ways you can provide input to bash commands.

STDIN Redirection from Here String

cat <<< "hello"

cat is concatenating the contents of the here string “hello”.

Note

This is identical to echo "hello". This example shows how a here string can be passed to a command as STDIN.

STDIN Redirection from File

cat < hello-from-bash.txt
Note

The hello-from-bash.txt file was created in the Redirect STDOUT Append File article.

cat is concatenating the contents of the file hello-from-bash.txt

Note

This is identical to cat hello-from-bash.txt. This is example shows how a file can be passed to a command as STDIN.

You will not be expected to know here strings, or STDIN redirection from files in this course.