繁体   English   中英

在bash脚本+ gnuplot脚本中使用Gnuplot变量而不是Bash Variable

[英]Use a Gnuplot variable instead of Bash Variable in a bash script + gnuplot script

您好我想在bash脚本中使用gnuplot绘制smth,所以我有:

#!/bin/bash
//myscript
gnuplot -persist <<-EOFMarker
        plot 'd.csv' using 3:xtic(1) with boxes notitle, 'd.csv' using 0:($3+100):3 with labels
EOFMarker

我的问题是脚本替换($ 3 + 100)来自bash变量(没有+ 100)而不是来自gnuplot(来自第3列+ 100的每个值)..如何更改脚本以便使用来自gnuplot的变量? 非常感谢

它应该工作, $3是空的,考虑这个:

#!/bin/bash
set a b world
cat <<-EOF
hello $3
EOF

将输出hello world 如果你想向命令发送$3 ,你需要逃避美元符号:

#!/bin/bash
set a b world
cat <<-EOF
hello \$3
EOF

使用column函数,然后你不必关心转义: $2column(2)的快捷方式。

gnuplot -persist <<-EOFMarker
    plot 'd.csv' using 3:xtic(1) with boxes notitle, 'd.csv' using 0:(column(3)+100):3 with labels
EOFMarker

顺便说一句:在绘制标签时,您可以使用offset选项指定偏移量,例如以字符为单位:

gnuplot -persist <<-EOFMarker
    plot 'd.csv' u 0:3:xtic(1) w boxes t '', '' u 0:3:3 w labels offset 0, char 1
EOFMarker

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM