在 bash 环境中将另一个文件中的命令插入到 gnuplot 脚本中
Inserting commands from another file into a gnuplot script in a bash environment
在我的 bash 脚本中,我在启动 gnuplot 脚本之前进行了一系列操作。我的 bash 脚本如下所示:
#!/bin/bash -e
# Do some bash operations here
# Create a file containing a list of Gnuplot commands called arrow_coords
# All the commands are the same: just drawing a group of arrows
# Every line in "arrow_coords" looks like this:
# set arrow from -500,-100 to 500,-100 as 1
# There are hundreds of those line commands
# Entering Gnuplot script
gnuplot <<- EOF
reset
set terminal pngcairo transparent nocrop enhanced font '$font_type, 22' size 1800,1800
set output "$output_file"
set yrange [-1:18]
set xrange [-1:18]
? <----------------------------------- HOW TO INSERT COMMANDS FROM ANOTHER FILE?
plot '$dat_file' using 1:2 with points ls 1
EOF
我找不到将 arrow_coords 中编写的命令插入 bash 文件中的 Gnuplot 脚本的方法。这可能吗?对于我正在尝试做的事情还有其他建议吗?
下面是一个说明解决方案的示例:
#!/bin/bash
# prepare file
echo "Test!" > test.txt
a=`cat test.txt`
cat <<- EOF
File contents: $a
Again: `cat test.txt`
EOF
所以在您的代码中,您可以将以 ?
开头的行替换为:
`cat the_file_you_generated`
如果您的文件只包含 gnuplot 指令,您可以 运行 使用 load
或 call
命令:
gnuplot <<- EOF
# your gnuplot configurations
load 'arrow_coords' # calling external file
plot '$dat_file' using 1:2 with points ls 1
EOF
在我的 bash 脚本中,我在启动 gnuplot 脚本之前进行了一系列操作。我的 bash 脚本如下所示:
#!/bin/bash -e
# Do some bash operations here
# Create a file containing a list of Gnuplot commands called arrow_coords
# All the commands are the same: just drawing a group of arrows
# Every line in "arrow_coords" looks like this:
# set arrow from -500,-100 to 500,-100 as 1
# There are hundreds of those line commands
# Entering Gnuplot script
gnuplot <<- EOF
reset
set terminal pngcairo transparent nocrop enhanced font '$font_type, 22' size 1800,1800
set output "$output_file"
set yrange [-1:18]
set xrange [-1:18]
? <----------------------------------- HOW TO INSERT COMMANDS FROM ANOTHER FILE?
plot '$dat_file' using 1:2 with points ls 1
EOF
我找不到将 arrow_coords 中编写的命令插入 bash 文件中的 Gnuplot 脚本的方法。这可能吗?对于我正在尝试做的事情还有其他建议吗?
下面是一个说明解决方案的示例:
#!/bin/bash
# prepare file
echo "Test!" > test.txt
a=`cat test.txt`
cat <<- EOF
File contents: $a
Again: `cat test.txt`
EOF
所以在您的代码中,您可以将以 ?
开头的行替换为:
`cat the_file_you_generated`
如果您的文件只包含 gnuplot 指令,您可以 运行 使用 load
或 call
命令:
gnuplot <<- EOF
# your gnuplot configurations
load 'arrow_coords' # calling external file
plot '$dat_file' using 1:2 with points ls 1
EOF