Pregunta

I'm trying to pass in a file and a single line of code into a program, say example.

My line:

i := 1;

My file (file):

blah1
blah2
blah3

Input to program:

i := 1;
blah1
blah2
blah3

I'm thinking it would be a one line such as:

example < `echo "i := 1;\n" cat file`

or something like that

¿Fue útil?

Solución

What you need is here string:

example <<< `echo "i:=1" && cat file`

From bash manual:

3.6.7 Here Strings

A variant of here documents, the format is:

     <<< word

The word is expanded and supplied to the command on its standard input. 

Otros consejos

{ echo 'i := 1;' ; cat myfile.txt ; } | example
(
echo "i := 1"
cat file
) | program
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top