views:

186

answers:

3

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 ?

+1  A: 

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

eval perl a.pl $CLI
Peter van der Heijden
It works. Thanks.
Galaxy
A: 
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

Abu Aqil
It cannot do redirect.
Galaxy
add eval in front
Abu Aqil
Your answer reads each line. The OP apparently only wants the first line (`sed "1 p"`). Also, if you are reading all the lines, instead of `cat|while`, you should use `done < a.lst`
Dennis Williamson
This is a job script for Grid Engine Job Array, `#$ -t 1-10` and `SEED=$(sed -n -e "$SGE_TASK_ID p" $SEEDFILE)` just reads each of the 10 lines for `$SEEDFILE`.
Galaxy
`done < a.lst`, How to write a similar script to this answer from "Abu Aqil" ? Seems `do echo $*;done<a.lst` is wrong.
Galaxy
A: 

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)
Dennis Williamson