Now gnuplot doesn't recognize the newline command "\"
unless I use "enter" in the vi-editor.
i.e. gnuplot -persist plot.gnu doesn't work
Similarly I found that commands are not recognized in Makefile if I don't specifically use "tab" space inside the vi-editor.
(I could have made a tab-space by using 'echo' in a shell script file, but that doesn't work!)
Thanks for the reply. I'll try this for tab. But what about the making newline instruction? What could be the way to resolve the problem in my first example?
Please explain better the problem you have with your first example with error messages if any. Newline is anyway unlikely an instruction per itself but probably a command separator.
Thanks. Let me try once again. My example may be specific to gnuplot. But it may arise to other cases.
If run the follwing commands :
#!/bin/bash
echo "plot \ " > temp
for f in 2 3
do
echo "x**"$f", \ " >> temp
done
echo "x**4" >> temp
cat temp | gnuplot -persist
rm -f temp
=======
I find the following error messages :
gnuplot> plot \
^
line 0: invalid character \
gnuplot> x**2, \
^
line 0: invalid character \
gnuplot> x**3, \
^
line 0: invalid character \
gnuplot> x**4
^
line 0: invalid command
====================
Whereas
echo "p x**2, x**3, x**4"|gnuplot -persist
works successfully though it's the same in principle.
Hope I could clarify this time. My observation is that the newline separator (" \") is not recognized by the shell always.
I have attached the shell script as well. You may need to install gnuplot in case it's not installed by your distribution.
\ at the end of the line is the only case where \ does not work as an escape character. Rather, it removes the linefeed character that follows altogether..
\ as the last character of the line removes the linefeed character that immediately follows (if it is interpreted by the shell (and some programs))
So:
plot 'datafile1' , \
'datafile2'
is the same as:
plot 'datafile1' , 'datafile2'
---------- Post updated at 10:22 ---------- Previous update was at 10:04 ----------
In your last example you use \ before a space instead of a linefeed, BTW. If it is used to remove a linefeed then it needs to be the last character on the line before the linefeed..
Yeah I totally agree. But that was not my purpose. I want to put datafile name at every line, as you can see that I am changing the name through the for-loop. At the same time I want to keep them as parts of instruction so that I can finally use in gnuplot.
In other word, can you modify the script so that it works? Like
echo "p x2, x3, x4"|gnuplot -persist But here I wish to plot for other powers in general, e.g. it can be extended to x5, x**6, etc., which will be decided by the for-loop.
So I feel that the " \" is not understood as a command in echo unless we use another "\" alongwith. Since if I don't remove the 'temp' file (as used in my script file), then "cat temp" gives
plot \
x2, \
x3, \
x**4
So one one slash has been used as an identifier of the other slash as a command.
Another important thing I required to do is to remove the extra space before the last quote, i.e.
\ "
should be replaced by
\\"
Hope this would help others who come across the same problem.
So it also belongs to the plotting in gnuplot using shell script
category.
\ is understood as a special character if used inside double quotes.. If you precede it with another backslash, it is taken literally, so the character "\" gets printed. This character is then given a special meaning by GNU plot since it is the last character before the linefeed and thus it indicates a continuation of the line..