0
votes

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
You didn't write how you invoke your script. Perhaps $1 is empty? - user1934428
What made you think that Utau_$elem= works the way you think? - U. Windl
@user1934428. I run my script on a terminal with ./file.sh. $1 refers to the first column of the files stat_AMD, stat_WALE and stat_SIM. It is not empty. - Martin7
@U.Windl. Thank you for your answer. I did not really understand what do you mean. Utau_$elem=$(awk 'FNR==5{print $1}' file_$elem) should take the value of awk 'FNR==5{print $1}' file_$elem which is a decimal number - Martin7
@Martin7 If I try (in bash): N=1;X$N=2, then I get If 'X1=2' is not .... So it does not set variable X1, and I guess that is what you tried (in other words). - U. Windl

1 Answers

0
votes

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.