Wednesday, June 29, 2011

Backslash at the end of a line

This tool is not essential for programming, but it can make our scripts more legible and easy to interpret. It is useful when you have to put several commands in the same script line but you preffer to separate them while working with your text editor. Then, the line:
  • plot 0 w l ls 0 notitle, 'whatever1.dat' u 1:2 w l lw 1 lt 3 notitle, 'whatever1.dat' u 1:3 w l lw 5 lt 1 notitle, 'whatever2.dat' u 1:2 w l lw 1 lt 3 notitle, 'whatever2.dat' u 1:3 w l lw 5 lt 1 notitle
is equivalent to:
  • plot \
  • 0 w l ls 0 notitle, \
  • 'whatever1.dat' u 1:2 w l lw 1 lt 3 notitle, \
  • 'whatever1.dat' u 1:3 w l lw 5 lt 1 notitle, \
  • 'whatever2.dat' u 1:2 w l lw 1 lt 3 notitle, \
  • 'whatever2.dat' u 1:3 w l lw 5 lt 1 notitle

This is not restricted to the plot command, but you can use it wherever you want. So:
  • set palette defined (0 "red", 1000 "orange", 1600 "dark-yellow", 1999 "yellow", 2000 "grey", 2001 "green", 2400 "dark-green", 3000 "cyan", 4000 "blue")
is again equivalent to:
  • set palette defined (\
  • 0 "red", \
  • 1000 "orange", \
  • 1600 "dark-yellow", \
  • 1999 "yellow", \
  • 2000 "grey", \
  • 2001 "green", \
  • 2400 "dark-green", \
  • 3000 "cyan", \
  • 4000 "blue")

Caution: Leaving a blank space after the backslash will result in a failure of the script.

    No comments:

    Post a Comment