2015-10-04 16 views
1

在我的bash腳本中,我在開始gnuplot腳本之前執行了一系列操作。我的bash腳本是這樣的:在bash環境中將命令從另一個文件插入gnuplot腳本

#!/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 

我無法找到一個方法來插入寫​​在arrow_coords進入gnuplot的腳本,我在我的bash文件中的命令。這可能嗎?對於我想要做的事情,還有其他建議嗎?

回答

2

下面是說明了解決方案的例子:

#!/bin/bash 

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

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

因此,在你的代碼,你可以代替開始?與線:

`cat the_file_you_generated` 
+0

工作就像魅力!謝謝。 – Theo

+0

不客氣。我很驚訝你使用bash並沒有遇到背景操作員! – Kenney

+0

我從來沒有用過它。我使用bash來開發相當簡單的腳本。所以我仍然是這方面的初學者;) – Theo

4

如果您的文件僅包含gnuplot的說明,您可以使用loadcall命令運行它:

gnuplot <<- EOF 
    # your gnuplot configurations 
    load 'arrow_coords' # calling external file 
    plot '$dat_file' using 1:2 with points ls 1 
EOF 
+0

很酷,這正是我所需要的。 :)這應該是首選的答案,更優雅。 –

相關問題