i am using GNUplot to create figures from data points, GNUplot works with simple scripts that contain simple parameters/variables like the range of the x or y axis, settings for line colors and stuff like that. When i call one of those scripts like:

gnuplot script1.gpl

it works fine, but when i run

gnuplot *.gpl

to run it for all files in the current directory, i got problems because some if the settings are transfered from one script to the next. This is probably because gnuplot does not resets the parameters and if i do not overwrite them explicitly in the following script, the settings are still there. Thats why i tried to run it differently using find:

find . -name '*.gpl' -exec gnuplot {} \;

but again i get the same problematic results. So what i need is a command that runs the same command for each file but in a way as if it where called manually for each file.

  • 1
    You may want to look up the reset and reset session Gnuplot commands – Thor Oct 25 '16 at 12:45
  • Why not make your scripts executable and start them with #!/usr/bin/gnuplot -c? Personally, I tend to make them Bash scripts that set up some variables, and use gnuplot << END followed by the plot script, followed by END, so that I can insert environment variables (using shell syntax, $name) into the script. But executable scripts anyway. I even often run them from Makefiles.. Let me know if you need a complex example. – Nominal Animal Oct 25 '16 at 13:21

I would expect find to work as per a single call. If there are no intermediate files being created I would suggest adding a bash (or other shell) prefix, to force it to be run in a sub-shell. Or you can try the following:

for i in *.gpl
  ( gnuplot "$i" )

The brackets will force a sub-shell, but I don't think it should be required.

  • Yes, this is exactly how find's -exec command '{}]' \; is expected to behave versus the alternative -exec command '{}' + where find's results are appended to create a singe multi-argument command (or as many as possible at least -minimising the instances of command being executed). This is also stated in man find. OP's find's behaviour seems oddish. – Fiximan Oct 25 '16 at 12:09
  • I guess it may depend on the commands he is using inside the .gpl files. Unfortunately, I can not post comments to ask simple questions. – Voltaire Oct 25 '16 at 13:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.