xargs is a command to read from stdin, which is a stream of data, and convert each line into arguments that are passed to another command.
Our hello_world.sh ex. 3 took in two command line arguments like this:
BabyMac:~ jennapederson$ ./hello_world.sh Jenna Pederson
But what if we only have a file of data? Using file redirection won't work because we are expecting command line arguments not stdin from a file.
BabyMac:~ jennapederson$ ./hello_world.sh < names.txt
Hello World, !
Instead we can use xargs to convert from stdin to arguments ex. 8.
BabyMac:~ jennapederson$ cat names.txt | xargs ./hello_world.sh
Hello World, Jenna Pederson!
Back: More Commands & Tools Forward: Back to the beginning