Using variables from shell script for gnuplot

421 views Asked by At

I try to plot several curves on a same plot using variables from a shell script. My problem is that I do not succeed in collecting the variables and use them in gnuplot.

Here is my code:

#!/bin/bash

for elem in AMD WALE SIM;
do
  echo $elem
  Utau_$elem=$(awk 'FNR==5{print $1}' file_$elem)
done
gnuplot -persist  <<-EOFMarker
list= "AMD WALE SIM"
plot for [i in list] "stat_".i u 1:($1/Utau_.i) @ title_i  
EOFMarker

This script aim at avoiding to write all the plot sentences but should have the same effect that the following :

 plot "stat_AMD" u 1:($1/Utau_AMD}) @title_AMD,\
"stat_WALE" u 1:($1/Utau_WALE}) @title_WALE,\
"stat_SIM" u 1:($1/Utau_SIM})  @title_SIM

I did not succeed in plotting anything and I am not sure that the link can be done between the value Utau_$elem for the bash script and Utau_.i from the gnuplot script. Does someone have an idea if it is possible and how can I code it ?

Thanks a lot !

1

There are 1 answers

0
Martin7 On BEST ANSWER

Thank @markp-fuso, it works !

I just had to replace "($1/${Utau_fr[${i}]})" by "(column(1)/${Utau_fr[${i}]})" because the dollar signs are interpreted as starting a shell variable.