我搜索了互联网,但也许我使用了错误的关键字,但我找不到下面这个简单问题的语法:
如何将文件作为命令行参数重定向到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
答案 0 :(得分:3)
尝试
$ touch $(< file.txt)
展开file.txt
的内容并将其作为参数提供给touch
答案 1 :(得分:1)
或者,如果您在文件中存储了多个文件名,则可以使用xargs
,例如,
xargs touch <file.txt
(它只适用于一个,但比简单的“回声”更灵活。)