Skip to content
Advertisement

How to run a file in variable

I want to run this command:
././pscan `cat ips` 22
but the script don’t run corectly

ips file:
1.1
2.2
3.3
4.4
5.5

and i want to run command e.g: ././pscan 1.1 22 ././pscan 2.2 22 ././pscan 3.3 22 ././pscan 4.4 22 ././pscan 5.5 22

the script pscan works perfectly when i type on single command ././pscan 1.1 22

and i want to run more than 5.5 e.g 100.241 etc..

Advertisement

Answer

Do you want to run your command with each line/word of your input? You can use a loop and read to achieve that:

while read line; do
  ./script.sh "$line" other args
done < input_file

or with xargs:

< input_file xargs -L1 -I{} ./script {} other args

Pay attention to how whitespace is (not) handled.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement