[英]Inserting commands from another file into a gnuplot script in a bash environment
[英]Bash script : put commands on several lines with gnuplot
當我在Bash中鍵入以下命令時,它運行良好(生成直方圖):
$ cat input.dat | gnuplot -p -e 'set style data histograms; set style histogram cluster gap 1; set style fill solid border -1; set boxwidth 0.05; binwidth=0.1 ; bin(x,width)=width*floor(x/width) + binwidth/2.0; plot "-" using (bin($1, binwidth)):(1) smooth freq with boxes'
我想將此命令放在一個文件中,並在多行上。 我為此嘗試:
#!/bin/bash
cat input.dat | gnuplot -p -e 'set style data histograms; set style histogram cluster gap 1; \
bin(x,width)=width*floor(x/width) + binwidth/2.0; \
plot "-" using (bin($1, binwidth)):(1) smooth freq with boxes'
但是當我執行這個shell腳本時,出現以下錯誤:
set style data histograms; set style histogram cluster gap 1; \
^
line -3: invalid character \
問題是我將gnuplot -p -e
命令分割在多行上,但在簡單的引號之間'... set style histogram cluster gap 1; \\ ... bin(x,width)=width*floor(x/width) + binwidth/2.0; \\ ... smooth freq with boxes'
'... set style histogram cluster gap 1; \\ ... bin(x,width)=width*floor(x/width) + binwidth/2.0; \\ ... smooth freq with boxes'
這與我們用反斜杠分隔linux命令時的情況不同:就我而言,我將2個簡單引號的內部塊分隔
有沒有辦法解決這個問題並拆分上面的第一個命令?
問候
如果用雙引號替換表達式周圍的單引號,而用單引號替換表達式-周圍的雙引號,則可以轉義$ 1,腳本應該可以工作:
cat input.dat | gnuplot -p -e "set style data histograms; set style histogram cluster gap 1; \
set style fill solid border -1; set boxwidth 0.05; binwidth=0.1 ; \
bin(x,width)=width*floor(x/width) + binwidth/2.0; \
plot '-' using (bin(\$1, binwidth)):(1) smooth freq with boxes"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.