Question

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

Was it helpful?

Solution

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. 

OTHER TIPS

{ echo 'i := 1;' ; cat myfile.txt ; } | example
(
echo "i := 1"
cat file
) | program
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top