在 BASH 中使用文件内容作为命令行参数 [英] Using file contents as command line arguments in BASH
本文介绍了在 BASH 中使用文件内容作为命令行参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道如何使用文件的内容作为命令行参数,但在语法上很挣扎.
I'd like to know how to use the contents of a file as command line arguments, but am struggling with syntax.
假设我有以下内容:
# cat > arglist
src/file1 dst/file1
src/file2 dst/file2
src/file3 dst/file3
如何使用 arglist
文件中每一行的内容作为参数来表示 cp
命令?
How can I use the contents of each line in the arglist
file as arguments to say, a cp
command?
推荐答案
xargs 的 '-n' 选项指定每个命令使用多少个参数:
the '-n' option for xargs specifies how many arguments to use per command :
$ xargs -n2 < arglist echo cp
cp src/file1 dst/file1
cp src/file2 dst/file2
cp src/file3 dst/file3
这篇关于在 BASH 中使用文件内容作为命令行参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文