gnuplot do not take my variable

Hi!

i want to print ot my data of the last seven days with gnuplot.
in a script i put my gnuplot-script and at the top i generate my date-variable.

  #/bin/bash -e
# Gnuplot script "API_Status.txt"
# set terminal postscript color landscape dl 2 lw 2 'Helvetica' 15 ;
# set output "status.eps"
# Variable - TIME
Z=7    # Zeitspanne
M=$`date +%m`
D=$`date +%d`
Ma=$`date --date="$Z days ago" +%m`
Da=$`date --date="$Z days ago" +%d`   
gnuplot -persist << EOF
#set terminal postscript eps color
set key off                             # 
#unset log                              # remove any log-scaling
#unset label                            # remove any previous labels
#set title "METE-Daten  - "
set xdata time
set timefmt "%m/%d/%y-%H%M%S"
set format x "%d.%m\n00:00"
set grid noxtics nomxtics ytics nomytics noztics nomztics \
 nox2tics nomx2tics noy2tics nomy2tics nocbtics nomcbtics
set xtics 86400                # x-Achsen-raster ein Tag in sec
set mxtics 4                # Aufteilung des Tages in 4 * 6h
set xrange [ "Ma/Da/12":"M/D/12" ]     # Zeitfenster festlegen
# set xlabel "Zeit (h)"

#Multiplot
#-----------------------
set multiplot
....

It give me the grafik, but over the complete month. My idea is, that

$`date --date="$Z days ago" +%m`

will not work properly. i tried allready to put it into brackets but without success. Maybe an alternetiv spefication of the time-variable?
Can someone help me?

Thanks in advance!
IMPe

I could be wrong, but the last line looks problematic:

You create some variables (D, M, Da, Ma) but you never use them. Instead you use fixed strings ("D", "M", ...).

If you want to use a variables content (as opposed to its name) you have to prepend it with "$". To avoid ambiguity you can also enclose the variables name with curly braces ("{}"). So the last line should probably look like this:

set xrange [ "${Ma}/${Da}/12":"${M}/${D}/12" ]

Further, you should not use the backticks, even if they work. Backticks are an ancient construct and only supported for legacy purposes. Use the "$(...)" instead. That means change:

M=`date +%m`

to

M="$(date +%m)"

and accordingly with similar lines.

I hope this helps.

bakunin

1 Like

Thanks a lot - you dedect all my failures!
It helps a lot!

IMPe