I need to run gnuplot scripts on different devices. The file structure is the same on the devices, once I get to a particular directory, but the paths to those directories are different. I think I need to have a variable in the path name that I can change according to which device I am on.
I thought the following would work, because I found something similar here, but it doesn't:
path_to_directory="/desktop/path/to/directory"
# path_to_directory="laptop/path/to/directory"
# the line above is commented out but it can be included
# if I want to switch from my desktop to my laptop
path_to_file="$path_to_directory/path/to/file"
plot path_to_file ...
A warning message says: Skipping unreadable file "$path_to_directory/path/to/file"
Do you know how I can include a variable in the path of a gnuplot script, so that I can switch easily between paths?
Thank you.
In gnuplot you don't use $ to indicate variables as you do in bash. You would do a concatenation operation with a dot:
path_to_directory="/desktop/path/to/directory"
path_to_file=path_to_directory."/path/to/file"
You simply need to concatenate two string variables with the . operator:
path_to_directory = "/desktop/path/to/directory"
path_to_file = path_to_directory . "/path/to/file"
plot path_to_file ...
You can also define a default path which can be overridden:
default_path_to_directory = "/desktop/path/to/directory"
if (!exists("path_to_directory")) path_to_directory = default_path_to_directory
path_to_file = path_to_directory . "/path/to/file"
plot path_to_file ...
Now you can override the path_to_directory but must not: e.g. when calling gnuplot like gnuplot -e "path_to_directory='...'" script.gp or with a configuration file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With