开发者

How to supply many argv and outputredirection with one bash var?

开发者 https://www.devze.com 2022-12-08 18:42 出处:网络
In file a.lst: in1.a in1.b > out1.a 2> out1.b in2.a in2.b > out2.a 2> out2.b In do.sh: CLI=$(sed -n -e \"1 p\" a.lst)

In file a.lst:

in1.a in1.b > out1.a 2> out1.b
in2.a in2.b > out2.a 2> out2.b

In do.sh:

CLI=$(sed -n -e "1 p" a.lst)
perl a.pl $CLI

I want to run like perl a.pl in1.a in1开发者_如何学运维.b > out1.a 2> out1.b, how can I make it work ?


I can't test it here, but it looks like using eval will work, so:

eval perl a.pl $CLI


cat a.lst | while read all
do
   eval perl a.pl $all
done

to evaluate the redirect part just add eval as posted by someone earlier


If your input file is in a consistent format (always the same number of parameters and the same kind of redirection), you might be able to do this:

CLI=($(head -n 1 a.lst))
perl a.pl "${CLI[0]}" "${CLI[1]}" > "${CLI[3]}" 2> "${CLI[5]}"

If you actually want to do this for each line in a.list:

while read -a CLI
do
    perl a.pl "${CLI[0]}" "${CLI[1]}" > "${CLI[3]}" 2> "${CLI[5]}"
done < a.lst

If you want just the first 10 lines of your input file, the last line can be changed to:

done < <(head -n 10 a.lst)
0

精彩评论

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