Mih*_*gil 11 command-line bash scripts gnuplot
我想要做的是编写一个脚本,它首先启动一个程序,然后告诉它执行一堆命令,然后退出。让我们举一个例子。
我写了这个脚本myscript.sh,但它没有按照我想要的方式工作。它所做的只是运行 gnuplot 并等待它退出,然后运行其他命令;这显然会产生错误。
#!/bin/bash
gnuplot
plot sin(x)
pause -1
quit
Run Code Online (Sandbox Code Playgroud)
我想我想做什么很清楚;如果没有,请在评论中告诉我。
wal*_*tor 18
一种方法是-persist:
#!/usr/bin/gnuplot -persist
set title "Walt pedometer" font ",14" textcolor rgbcolor "royalblue"
set timefmt "%y/%m/%d"
set xdata time
set pointsize 1
set terminal wxt enhanced title "Walt's steps " persist raise
plot "/home/walt/var/Pedometer" using 1:2 with linespoints
Run Code Online (Sandbox Code Playgroud)
另一种方法是,如果您需要预处理数据,则使用 Bash Here Document(请参阅参考资料man bash):
#!/bin/bash
minval=0 # the result of some (omitted) calculation
maxval=4219 # ditto
gnuplot -persist <<-EOFMarker
set title "Walt pedometer" font ",14" textcolor rgbcolor "royalblue"
set timefmt "%y/%m/%d"
set yrange $minval:$maxval
set xdata time
set pointsize 1
set terminal wxt enhanced title "Walt's steps " persist raise
plot "/home/walt/var/Pedometer" using 1:2 with linespoints
EOFMarker
# rest of script, after gnuplot exits
Run Code Online (Sandbox Code Playgroud)
Byt*_*der 12
来自man gnuplot或其在线联机帮助页:
-p, --persist lets plot windows survive after main gnuplot program
exits.
-e "command list" executes the requested commands before loading the
next input file.
Run Code Online (Sandbox Code Playgroud)
因此,您可能想要运行以下命令:
gnuplot -e "plot sin(x); pause -1"
Run Code Online (Sandbox Code Playgroud)
我提出的其他变体但不是那么有用:
gnuplot -p -e "plot sin(x); pause -1"
gnuplot -e "plot sin(x)"
gnuplot -p -e "plot sin(x)"
Run Code Online (Sandbox Code Playgroud)