我试图将一个文件和一行代码传入程序,例如。将行和文件内容作为stdin传递给程序
我行:
i := 1;
我的文件(文件):
blah1
blah2
blah3
输入到程序:
i := 1;
blah1
blah2
blah3
我想这将是一个行如:
example < `echo "i := 1;\n" cat file`
或类似的东西
我试图将一个文件和一行代码传入程序,例如。将行和文件内容作为stdin传递给程序
我行:
i := 1;
我的文件(文件):
blah1
blah2
blah3
输入到程序:
i := 1;
blah1
blah2
blah3
我想这将是一个行如:
example < `echo "i := 1;\n" cat file`
或类似的东西
你需要的是这里的字符串:
example <<< `echo "i:=1" && cat file`
从bash的手册:
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
不,重定向到一个名为'文件程序“,并且你缺少一个命令分隔符。 – tripleee
对不起,评论似乎已经在黄输入框?? – tripleee
它可以工作,因为它分成多行。它可以在一行中完成,但是如果可以的话我更喜欢这样的东西 - 特别是在脚本文件中。 Bash和Ksh都允许通过终端中的多条线路进行命令输入。 –