I'd like to know how to use the contents of a file as command line arguments, but am struggling with syntax.
Say I've got the following:
# cat > arglist
src/file1 dst/file1
src/file2 dst/file2
src/file3 dst/file3
How can I use the contents of each line in the arglist
file as arguments to say, a cp
command?
the '-n' option for xargs specifies how many arguments to use per command :
You can use pipe (|) :
or input redirection (<)
or xargs
Then you may use awk to get arguments:
Hope this helps..
Using
read
(this does assume that any spaces in the filenames inarglist
are escaped):If the arguments in the file are in the right order and filenames with spaces are quoted, then this will also work:
if your purpose is just to cp those files in thelist
Use
for
loop withIFS
(Internal Field Separator) set tonew line