Search code examples
bashgnuplotquotes

How to have three quote marks in gnuplot's oneliner?


Assume your pseudocode is where the mistake is with two times using the quotes "

gnuplot - e "set output 'tmp.png'; set_label(x,text) = sprintf("set label '%s' at cos(%f)", text, x, x)

which is wrong.

How can you have three types of quotes in gnuplot one-liner?


Solution

  • You must simply escape the second double quote characters for the shell (not for gnuplot!) with a backslash:

    gnuplot -e "set output 'tmp.png'; set_label(x,text) = sprintf(\"set label '%s' at cos(%f)\", text, x, x)"
    

    Alternatively, you can use gnuplot's mechanism of escaping: use double single quotes to escape one single quote character:

    gnuplot -e "set output 'tmp.png'; set_label(x,text) = sprintf('set label ''%s'' at cos(%f)', text, x, x)"