Otorrinolaringologista -man Otorrinolaringologista -man - 1 month ago 12
Bash Question

Shell Script: Passing each line as an argument to another script

Good day.

At work i have a script that receives a number as an argument and it shows me some information related to that number as an output.

The thing is some times i receive a huge list of numbers and executing this script numerous times during the day takes a lot of my time.

I would like to know if there is a way to save all those numbers on a file and direct each line of said file to be executed by the script.

Lets say my file contains the following numbers:


and the script is executed as follows:

sh script.sh 55(Number) go

Thanks in advance.


One way to accomplish that is using xargs, for example:

xargs -I{} sh script.sh 55{} go < numbers.txt

This assumes that you put your numbers in a file named numbers.txt. For each line in the file, the {} in sh script.sh 55{} go will be replaced with the value in the line.

For example:

xargs -I{} echo number is: {} < input

Given your sample input, the above will produce:

number is: 999999999
number is: 888888888
number is: 777777777
number is: 666666666
number is: 555555555