如何使用文件的行作为命令的参数? [英] How do I use the lines of a file as arguments of a command?
本文介绍了如何使用文件的行作为命令的参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
说,我有一个文件foo.txt
指定N
自变量
Say, I have a file foo.txt
specifying N
arguments
arg1
arg2
...
argN
我需要传递给命令my_command
如何使用文件的行作为命令的参数?
How do I use the lines of a file as arguments of a command?
推荐答案
如果您的shell是bash(以及其他),则$(cat afile)
的快捷方式是$(< afile)
,因此您应该这样写:
If your shell is bash (amongst others), a shortcut for $(cat afile)
is $(< afile)
, so you'd write:
mycommand "$(< file.txt)"
记录在命令替换"部分的bash手册页中.
Documented in the bash man page in the 'Command Substitution' section.
或者,从stdin读取命令,所以:mycommand < file.txt
Alterately, have your command read from stdin, so: mycommand < file.txt
这篇关于如何使用文件的行作为命令的参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文