gnuplot 内部列参数与容器 bash 脚本参数冲突
gnuplot internal column argument clashes with container bash script arguments
我在 bash 脚本中有以下代码,用于准备要绘图的输入数据。
当在 gnuplot 解释器中 运行 时,代码执行正常,但在 bash 脚本中,它替换了 $2,后者表示 ${outdir}/counts.txt 的第 2 列第二个 bash 参数的数据文件(输入文件与情节无关)
我如何编辑它以使 $1 和 $2 对 gnuplot 块保持私有?
#!/bin/bash
.. bash code
gnuplot <<-EOFMarker
set datafile separator ","
set key autotitle columnhead
set style line 1 \
linecolor rgb '#0060ad' \
linetype 1 linewidth 2 \
pointtype 7 pointsize 1.5
set yrange [*:100]
set xlabel "mappability %"
set ylabel "% above threshold"
max(a,b)=a>b?a:b
a=-99999999.
set terminal pngcairo
set output 'mappability_plot.png'
plot '${outdir}/counts.txt' using 1:(a=max(a,),0/0) notitle, \
'' using 1:(100*/a) notitle with linespoints linestyle 1
EOFMarker
而不是 </code> 和 <code>
,尝试 column(1)
和 column(2)
...
您可以通过使用反斜杠转义 $
字符来防止 shell 在此处文档中展开 $something
:
gnuplot <<-EOFMarker
[...]
plot '${outdir}/counts.txt' using 1:(a=max(a,$2),0/0) notitle, \
'' using 1:(100*$2/a) notitle with linespoints linestyle 1
EOFMarker
注意 ${outdir}
没有转义,所以 shell 会继续并正常替换它。顺便说一句,您还需要转义您想要传递给程序而不被解释的任何反引号或反斜杠(转义)字符。
顺便说一句,它不适用于此处,但您可以通过引用分隔符来关闭此处文档中的 所有 替换:
gnuplot <<-'EOFMarker'
$things `that` $won't \be $expanded
EOFMarker
在这里不起作用的原因是它也会阻止 shell 扩展 ${outdir}
,我想这不是你想要的。
我在 bash 脚本中有以下代码,用于准备要绘图的输入数据。
当在 gnuplot 解释器中 运行 时,代码执行正常,但在 bash 脚本中,它替换了 $2,后者表示 ${outdir}/counts.txt 的第 2 列第二个 bash 参数的数据文件(输入文件与情节无关)
我如何编辑它以使 $1 和 $2 对 gnuplot 块保持私有?
#!/bin/bash
.. bash code
gnuplot <<-EOFMarker
set datafile separator ","
set key autotitle columnhead
set style line 1 \
linecolor rgb '#0060ad' \
linetype 1 linewidth 2 \
pointtype 7 pointsize 1.5
set yrange [*:100]
set xlabel "mappability %"
set ylabel "% above threshold"
max(a,b)=a>b?a:b
a=-99999999.
set terminal pngcairo
set output 'mappability_plot.png'
plot '${outdir}/counts.txt' using 1:(a=max(a,),0/0) notitle, \
'' using 1:(100*/a) notitle with linespoints linestyle 1
EOFMarker
而不是 </code> 和 <code>
,尝试 column(1)
和 column(2)
...
您可以通过使用反斜杠转义 $
字符来防止 shell 在此处文档中展开 $something
:
gnuplot <<-EOFMarker
[...]
plot '${outdir}/counts.txt' using 1:(a=max(a,$2),0/0) notitle, \
'' using 1:(100*$2/a) notitle with linespoints linestyle 1
EOFMarker
注意 ${outdir}
没有转义,所以 shell 会继续并正常替换它。顺便说一句,您还需要转义您想要传递给程序而不被解释的任何反引号或反斜杠(转义)字符。
顺便说一句,它不适用于此处,但您可以通过引用分隔符来关闭此处文档中的 所有 替换:
gnuplot <<-'EOFMarker'
$things `that` $won't \be $expanded
EOFMarker
在这里不起作用的原因是它也会阻止 shell 扩展 ${outdir}
,我想这不是你想要的。