在ubuntu下使用gnuplot時,每畫一個圖需要在終端下數圖多個命令,這樣效率很低。
我們知道shell腳本可以對命令進行批處理,於是就想到將這多個命令寫到一個shell腳本中。
首先,做了一下嘗試:
代碼:文件名:testPlot.sh
1 #!/bin/bash 2 gnuplot 3 4 set title "Node4 Local Clock" 5 plot '/home/jing/m_allFile/project/SourceInsight-AS/AS/SourecinsightProject/AS-Source/ASRedundancy/ns-allinone-3.25/ns-3.25/nodeLocalTime4' with linespoints pt 7 6 plot '' with linespoints pt 7
其中,第一個 plot 后的是我的文件路徑,因為這樣就會將整個路徑都輸出到圖中,所以會有第二個plot.
在終端運行命令:1.先切到testPlot.sh所在目錄
2.運行命令:sh testPlot.sh
之后,會進入到gnuplot命令中,然后輸入 exit,報錯
testPlot.sh: 5: testPlot.sh: plot: not found
testPlot.sh: 6: testPlot.sh: plot: not found
最開始,認為是bash不支持gnuplot,然后換了好幾個其他的shell,還是沒有解決。
最后,通過如下方式解決:
代碼:
1 #!/bin/bash 2 3 gnuplot -persist <<EOF 4 5 set title "Node4 Local Clock" 6 plot '/home/jing/m_allFile/project/SourceInsight-AS/AS/SourecinsightProject/AS-Source/ASRedundancy/ns-allinone-3.25/ns-3.25/nodeLocalTime4' with linespoints pt 7 7 plot '' with linespoints pt 7 8 9 EOF
此代碼可以畫出正確的數據。
