#!/bin/bash
inputfile="${1}" #you could even do some getopt magic here...
################################################################################
## generate a gnuplotscript, strip off bash header
gnuplotscript=$(mktemp /tmp/gnuplot_cmd_$(basename "${0}").XXXXXX.gnuplot)
firstline=$(grep -m 1 -n "^#!/usr/bin/gnuplot" "${0}")
firstline=${firstline%%:*} #remove everything after the colon
sed -e "1,${firstline}d" < "${0}" > "${gnuplotscript}"
################################################################################
## run gnuplot
/usr/bin/gnuplot -e "inputfile=\"${inputfile}\"" "${gnuplotscript}"
status=$?
if [[ ${status} -ne 0 ]] ; then
echo "ERROR: gnuplot returned with exit status $?"
fi
################################################################################
## cleanup and exit
rm -f "${gnuplotscript}"
exit ${status}
#!/usr/bin/gnuplot
plot inputfile using 1:4 with linespoints
#... or whatever you want
我的实现稍微复杂一些(例如,替换 sed 调用中的一些魔术标记,而我已经在做了... ...) ,但是为了更好地理解,我简化了这个示例。
你也可以让它变得更简单... ... YMMV。