BAM*_*con 1 bash io-redirection
我有这两步bash命令:
L=`wc -l testfile | cut -d' ' -f1`
myprogram testfile $L testfile.out
Run Code Online (Sandbox Code Playgroud)
长话短说,myprogram
需要将行数作为输入.
我想把它组合成一行.
这并没有工作,因为使用的是重定向|
到-
通行证标准输出流作为一个文件,而不是一个字符串.
wc -l testfile | cut -d' ' -f1 | myprogram testfile - testfile.out
Run Code Online (Sandbox Code Playgroud)
有没有办法将它组合成一行?
使用流程替换:
myprogram testfile $(wc -l < testfile) testfile.out
^^^^^^^^^^^^^^^^^^^
Run Code Online (Sandbox Code Playgroud)
这样,wc -l < testfile
与程序的调用一起评估,并且两个命令组合在一起.
注意只wc -l < file
返回数字,因此您不必执行cut
任何其他操作来清除输出.