Reputation: 335
I saw the code written for testing our code with input from termial:
./spellcheck corpus_colors <<< rend
corpus_colors
is the filename, I guess rend
is for terminal input.
<<<
behaves as terminal input?
Upvotes: 1
Views: 196
Reputation: 295443
<<<
is a bash extension (not available in baseline POSIX shells) which redirects literal content to stdin (with an added trailing newline). It is implementation-defined whether it appears to be a pipeline or a temporary file. It does not act as a terminal -- that is to say, isatty()
will fail.
Compared to
echo rend | ./spellcheck corpus_colors
...using
./spellcheck corpus_colors <<<rend
can be slightly more efficient, avoiding the extra subshell needed to set up a pipeline. Avoiding this subshell also means that an operation can be a shell function which changes shell state, and these state changes can persist past the end of the function's execution.
See the wikipedia article on "here strings", or (better) the relevant component of the bash manual.
Upvotes: 5
Reputation: 785
You can use certain characters to redirect both input and output.
Examples ...
./someprogram > foo.txt
Will replace the file foo.txt
( or create it ) and add the standard output of someprogram
./someprogram >> foo.txt
Will append the standard output of someprogram
to the file foo.txt
( creating it if necessary )
./someprogram < foo.txt
Will use the contents of foo.txt
as standard input for someprogram
./someprogram | someotherprogram
Will redirect the standard output of someprogram
and use it as the standard input for someotherprogram
./someprogram < foo.txt > bar.txt
Will use the contents of foo.txt
and the standard input of someprogram
and redirect the standard output of someprogram
to the file bar.txt
./someprogram <<< rends
Will use "rends\n" ( without the quotes ) as standard input for someprogram
This page has some good information on that topic.
Upvotes: 2
Reputation: 21
Under BASH <<<
is used to specify a 'Here String'. It's an inline version of a 'Here Document'. What ever comes after <<<
is fed into stdin of the calling program. It is similar to echoing through a pipe to a command. More information can be found here:
http://tldp.org/LDP/abs/html/x17837.html
Upvotes: 2