1

In my bash script, I am doing a bunch of operations before starting my gnuplot script. My bash script looks like this:

    #!/bin/bash -e

    # Do some bash operations here

    # Create a file containing a list of Gnuplot commands called arrow_coords
    # All the commands are the same: just drawing a group of arrows
    # Every line in "arrow_coords" looks like this: 
    # set arrow from -500,-100 to 500,-100 as 1
    # There are hundreds of those line commands 

    # Entering Gnuplot script

    gnuplot <<- EOF
    reset
    set terminal pngcairo transparent nocrop enhanced font '$font_type, 22' size 1800,1800
    set output "$output_file"
    set yrange [-1:18]
    set xrange [-1:18]
    ? <----------------------------------- HOW TO INSERT COMMANDS FROM ANOTHER FILE?
    plot '$dat_file' using 1:2 with points ls 1
    EOF

I could not find a way to insert the commands written in arrow_coords into the Gnuplot script I have in my bash file. Is this possible? Are there other suggestions to what I am trying to do?

2 Answers 2

4

If your file contains only gnuplot instructions, you can run it with the load or call commands:

gnuplot <<- EOF
  # your gnuplot configurations
  load 'arrow_coords'    # calling external file 
  plot '$dat_file' using 1:2 with points ls 1
EOF
Sign up to request clarification or add additional context in comments.

1 Comment

Cool, this is exactly what I needed. :) This should be the preferred answer imho, much more elegant.
2

Here's an example that illustrates the solution:

#!/bin/bash

# prepare file    
echo "Test!" > test.txt

a=`cat test.txt`
cat <<- EOF
File contents: $a
Again: `cat test.txt`
EOF

So in your code, you could replace the line starting with ? with:

`cat the_file_you_generated`

3 Comments

Worked like charm! Thanks.
You're welcome. I'm surprised you use bash and have not come across the backtic operator!
I've never used it before. I use bash to develop fairly easy scripts. So I am still a beginner in that respect ;)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.