プログラム例
#!/bin/sh
loop=true
while [ "$loop" = true ]
do
read -p "入力ファイル : " input_file
read -p "出力ファイル : " output_file
if [ ! -f "$input_file.csv" ]; then
echo "入力ファイルが見つかりません。"
continue
fi
read -p "x軸のプロット範囲 ex.始値 増分 終値 : " x_start x_inc x_finish
read -p "y軸のプロット範囲 ex.始値 増分 終値 : " y_start y_inc y_finish
gnuplot <<EOF
set encoding cp932
set terminal pngcairo
set datafile separator ","
set output "$output_file.png"
set tics font "Times New Roman, 12"
set xlabel font "Times New Roman, 12"
set ylabel font "Times New Roman, 12"
set key font "Times New Roman, 12"
set key right
set xlabel "x"
set xtics $x_start, $x_inc, $x_finish
set xrange [$x_start:$x_finish]
set ylabel "y"
set ytics $y_start, $y_inc, $y_finish
set yrange [$y_start:$y_finish]
plot "$input_file.csv" using \$1:\$2 title "" w l lc rgb "black"
EOF
read -p "保存しますか [y/n] : " save_file
if [ "$save_file" = "n" ]; then
rm "$output_file.png"
fi
read -p "終了しますか [y/n] : " finish
if [ "$finish" = "y" ]; then
loop=false
fi
done
注意点
通常,csvファイルの列指定の際に\はいりませんが,シェルスクリプトの場合,シェルとgnuplotの変数を区別する必要があるため\が必要になります.それ以外の書き方は同じです.