3

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.

2 Answers 2

5

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"
Sign up to request clarification or add additional context in comments.

Comments

3

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.

Comments

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.