开发者

Passing lines as args to a script

开发者 https://www.devze.com 2022-12-25 22:07 出处:网络
How do I pass each line from a text file as an argument to a script I have written? So each line is then in itself a sin开发者_运维问答gle arg to the script each time.cat file | xargs --replace script

How do I pass each line from a text file as an argument to a script I have written? So each line is then in itself a sin开发者_运维问答gle arg to the script each time.


cat file | xargs --replace script {}

I should note that if you want each line of the file to be treated as one argument to your script, add quotes as appropriate to the {}, most likely \"{}\"


No need for cat

xargs -I {} --arg-file input-file script_file {}


you can do this

while read -r line
do
  ./script_i_have_written.sh "$line"
done <"file"

but why do that when in your "script_i_have_written.sh", you can parse the text file straight away

#!/bin/bash
# script_i_have_written.sh
while read -r line
do 
  echo "do something with $line"
done <"file"
0

精彩评论

暂无评论...
验证码 换一张
取 消