gpt4 book ai didi

linux - 将命令作为变量传递给另一个程序?

转载 作者:太空宇宙 更新时间:2023-11-04 12:03:09 25 4
gpt4 key购买 nike

我正在创建一个交互式脚本,允许我使用 Gnuplot 绘制数据文件的特定部分。这些文件包含多个仪器数据通道,我想在绘图上一起绘制指定的 channel 。目前我只能用脚本独立绘制每个 channel 。

for ycolumn in $ycolumns; do 

gnuplot -p << EOF
set datafile separator ","
set autoscale
set grid
set xlabel "Time"
set ylabel "Data"
set title "$graphTitle"
plot "$FILE" using $xcolumn:$ycolumn lt rgb "red" with lines t " "
EOF

这是独立绘制每个 channel 的代码。为了将它们绘制在一起,我需要让绘图线看起来像这样

plot "$FILE" using $xcolumn:$ycolumn1 lt with lines t " ","$FILE" using $xcolumn:$ycolumn2 lt with lines t " ", etc...

我的问题是,如果可能的话,我如何在 gnuplot 之外有一个 for 循环,将每个列命令(“$FILE”使用 $xcolumn:$ycolumn1 lt 和行 t“”)附加到一个变量,然后那个变量被传递给 Gnuplot 中的 plot 命令?

我正在考虑使用 expect,但我想不出一种方法来实现它,就像我尝试自动化该脚本一样。

最佳答案

可能最直接的方法是首先组装整个 plot 命令(如“那个人”的评论中提到的),然后在此处的文档中使用它:

plotCmd=""
plotCmdDelim="plot"
for ycolumn in $ycolumns
do
plotCmd="${plotCmd}${plotCmdDelim} '${FILE}' using $xcolumn:$ycolumn lt rgb 'red' with lines t ' '"
plotCmdDelim=","
done

gnuplot -p << EOF
set datafile separator ","
set autoscale
set grid
set xlabel "Time"
set ylabel "Data"
set title "$graphTitle"
${plotCmd}
EOF

关于linux - 将命令作为变量传递给另一个程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51661718/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com