本文介绍了在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中将文件内容用作命令行参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!