문제

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

도움이 되었습니까?

해결책

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. 

다른 팁

{ echo 'i := 1;' ; cat myfile.txt ; } | example
(
echo "i := 1"
cat file
) | program
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top