You already have an answer telling you how to use xargs
. In my experience xargs
is useful when you want to run a simple command on a list of arguments that are easy to retrieve. In your example, xargs
will do nicelly. However, if you want to do something more complicated than run a simple command, you may want to use a while
loop:
while IFS=$'\t' read -r a b
do
mkdir -p "$b"
done <filemappings.txt
In this special case, read a b
will read two arguments separated by the defined IFS
and put each in a different variable. If you are a one-liner lover, you may also do:
while IFS=$'\t' read -r a b; do mkdir -p "$b"; done <filemappings.txt
In this way you may read multiple arguments to apply to any series of commands; something that xargs
is not well suited to do.
Using read -r
will read a line literally regardless of any backslashes in it, in case you need to read a line with backslashes.
Also note that some operating systems may allow tabs as part of a file or directory name. That would break the use of the tab as the separator of arguments.