[英]How to pass output as command line argument in bash?
I have this two step bash command: 我有这两个步骤bash命令:
L=`wc -l testfile | cut -d' ' -f1`
myprogram testfile $L testfile.out
Long story short, myprogram
needs the line count as an input. 长话短说,
myprogram
需要行数作为输入。
I want to combine this into one line. 我想将其合并为一行。
This does not work because using redirect |
因为使用的是重定向这不起作用
|
to -
passes stdout stream as a file, not a string. 到
-
通过标准输出流作为一个文件,而不是一个字符串。
wc -l testfile | cut -d' ' -f1 | myprogram testfile - testfile.out
Is there a way to combine this into one line? 有没有办法将其组合成一条线?
Use process substitution: 使用流程替代:
myprogram testfile $(wc -l < testfile) testfile.out
^^^^^^^^^^^^^^^^^^^
This way, wc -l < testfile
is evaluated together with the call of the program and you have both commands combined. 这样,
wc -l < testfile
与程序调用一起被评估,并且您将两个命令组合在一起。
Note wc -l < file
returns you just the number, so you don't have to do cut
or any other thing to clean the output. 注意
wc -l < file
仅返回数字,因此您不必执行cut
或其他任何操作来清理输出。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.