2014-11-05 18 views
2

我需要在不同的設備上運行gnuplot腳本。一旦我到達特定目錄,設備上的文件結構是相同的,但這些目錄的路徑不同。我想我需要在路徑名中包含一個變量,以便根據我所在的設備進行更改。gnuplot在文件路徑中有一個變量

我想下面會的工作,because I found something similar here,但它並不:

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 ... 

一條警告消息說:跳過不可讀文件 「$ path_to_directory /路徑/到/文件」

你知道如何在gnuplot腳本的路徑中包含變量,以便我可以在路徑之間輕鬆切換?

謝謝。

回答

3

在gnuplot中,您不使用$來指示變量,就像在bash中做的那樣。你會做一個級聯操作以點:

path_to_directory="/desktop/path/to/directory" 
path_to_file=path_to_directory."/path/to/file" 
3

你只需要連接兩個字符串變量與.操作:

path_to_directory = "/desktop/path/to/directory" 
path_to_file = path_to_directory . "/path/to/file" 
plot path_to_file ... 

你也可以定義可覆蓋的默認路徑:

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 ... 

現在你可以覆蓋path_to_directory但不得:如當調用像gnuplot -e "path_to_directory='...'" script.gp gnuplot或與配置文件。