I am wondering about the way the redirection <<< works in bash. I understand that it redirects the chain after it to the command before as if the content was in virtual file. Examples

$ cut -d. -f1 <<< A.B
$ cut -d. -f1 <<< 'A.B
> C.D'

But I don't understand what it does when used multiple times. Example

$ cut -d. -f1 <<< A.B <<< C.D

I would have expected the following output


Why does the shell only take into account the last redirection ? How could I add a virtual line to a file ? I would like to do something like the following example, such that command takes the virtual line and then processes the file my_file.

command <<< "virtual line" my_file 

Note : I'm using bash version 4.4.12(1)-release (x86_64-pc-linux-gnu).


<<< redirects the stdin. If you redirect stdin and then redirect it again, the first redirection gets lost.

If the command has a way of saying "process stdin", which e.g. for cat is a dash, you can prepend a line in this way:

cat - input_file <<< 'virtual line'
  • Thank you for your answer. It clarifies the way redirections are performed. – Tom-Tom Mar 13 at 14:27

Offering an alternative to choroba's answer, you can construct more complete input using syntax such as:

command  << EOF
virtual line
`cat input_file`

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.