execution of a string being echoed in bash

hi all, I am trying to do a loop on a series of plotting function shown below:

colorlist=(blue red green); n=0;
for k in $xy; do
     psbasemap $range -JM$scale -B10g5 -X1 -Y1 -P -K > $outfile
     pscoast $range -JM$scale -B10g5 -D$res -P -W$lwidth -G$fill -O -K >> $outfile
     echo "psxy $k $range -JM$scale -B10g5 -Sc0.05 -P -G${colorlist[n++]} -O -K >> $outfile"
 done

I want to execute the command string being echoed and that for the last file to be executed within the list, it will omit the -K option. I need to run it like this sample code below:

psxy 1999.dat -R$range -JM$scale -P -M -Sc0.1 -Gblue -K -O >> $outfile
psxy 2000.dat -R$range -JM$scale -P -M -Sc0.1 -Gred -K -O >> $outfile
psxy 2001.dat -R$range -JM$scale -P -M -Sc0.1 -Ggreen -O >> $outfile

bunch of thanks!

nvm, misunderstood :slight_smile: