将参数从文件重定向到Linux命令

时间:2015-05-26 23:30:44

标签: linux shell

我搜索了互联网,但也许我使用了错误的关键字,但我找不到下面这个简单问题的语法:

如何将文件作为命令行参数重定向到Linux命令" touch"?我想使用"触摸abc.txt"创建一个文件,但文件名应来自文​​件名" file.txt"其中包含" abc.txt",而非手动输入。

[root@machine ~]# touch < file.txt
touch: missing file operand
Try `touch --help' for more information.
[root@machine ~]# cat file.txt
abc.txt

2 个答案:

答案 0 :(得分:3)

尝试

$ touch $(< file.txt)

展开file.txt的内容并将其作为参数提供给touch

答案 1 :(得分:1)

或者,如果您在文件中存储了多个文件名,则可以使用xargs,例如,

xargs touch <file.txt

(它只适用于一个,但比简单的“回声”更灵活。)