用于使用 gnuplot 绘图的 Bash 脚本
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16520562/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Bash script for plotting with gnuplot
提问by user2377455
Hy guys! I have problems with writing bash script to run 50 times my script which generates data files and then plot it to file. I wrote smth like this, but it doesnt work
嘿伙计们!我在编写 bash 脚本以运行我的脚本 50 次时遇到问题,该脚本生成数据文件然后将其绘制到文件中。我是这样写的,但它不起作用
#!/bin/bash
for i in {1..50}
do
./ampl ampltst1 # generates different res.txt file each time
/usr/bin/gnuplot <<\__EOF
set xrange [-2:2]
set yrange [-2:2]
set term png
set output "image-${i}.png"
plot "res.txt" u 1:2 w lines, "res.txt" u 3:4 w lines, "res.txt" u 5:6 w li$
pause -1
__EOF
done
Please help me to fix this script!
请帮我修复这个脚本!
回答by loentar
Possibly you have problems with indentation: __EOFmust be without any leading spaces:
可能你有缩进问题:__EOF必须没有任何前导空格:
...
/usr/bin/gnuplot <<\__EOF
set xrange [-2:2]
...
__EOF
done
Also \symbol is not required.
也\没有所需的符号。
Also content of HERE-IS-DOCUMENT will be indented. Is that OK for gnuplot?
HERE-IS-DOCUMENT 的内容也将缩进。gnuplot 可以吗?
If no, you must remove indentation:
如果不是,则必须删除缩进:
for i in {1..50}
do
./ampl ampltst1 # generates different res.txt file each time
/usr/bin/gnuplot <<__EOF
set xrange [-2:2]
set yrange [-2:2]
set term png
set output "image-${i}.png"
plot "res.txt" u 1:2 w lines, "res.txt" u 3:4 w lines, "res.txt" u 5:6 w li$
pause -1
__EOF
done

