Entering a line on the command line simulating a file?

I have seen this technique before, but I don’t know what it called and forgot the exact syntax. Let's say I need to transfer the file to the program, for example: command <Enter file. However, I want to directly pass these lines of the input file to the command without an intermediate input file. It looks something like this, but it does not work:

command < $(file-line1; file-line2; file-line3)

Can someone tell me what this is called and how to do it?

+5
source share
4 answers

It is called Process Substitution

command < <(printf "%s\n" "file-line1" "file-line2" "file-line3")

, command , , /dev/fd/XX, "XX" - . , ( ), , printf.

+9

Herestring.

command <<< $'line 1\nline 2\nline 3\n'

heredoc.

command << EOF
line 1
line 2
line 3
EOF
+1

I think you mean "here is the document." Like this

#!/bin/sh
cat <<EOF
This is
the 
lines.
EOF
+1
source

What about:

cat myfile.txt | head -n3 | command
0
source

All Articles