Octave 将变量解析为 shell 脚本

Octave parse variable to shell script

我有 shell 脚本,其中包含不同的脚本,我使用 shell 脚本将它们全部连接到一个自动化进程。我尝试处理雷达图像,我需要使用 Octave 进行一些计算 -> 分类阈值。

我想将计算结果从 Octave 解析为 shell 脚本,这样我就可以将它用作另一个脚本的命令输入变量。我不想将八度输出写入文件,因为将有数百个图块需要处理。有没有一种方法可以将计算变量从八度脚本解析为 shell 脚本?

编辑:我已经根据评论

通过简单示例更改了我的长代码

基本示例:

以八度计算。

#!/usr/bin/env octave
# file: octave.m
result= 1 + 2

将其作为变量解析到 shell 脚本。

  #!/bin/sh
  octave octave.m # I want to get one number value 
  # some method to get result from octave script
  ./shell2.sh result

在另一个脚本中使用该变量。

   #!/bin/sh
   #file: shell2.sh
   echo result

正如我在评论中所说:让 GNU Octave return stdout 上的值:

zubro.sh:

#!/bin/sh
# filename of this script is zubro.sh
result=`octave zubro.m`
./shell2.sh "$result"

zubro.m:

# filename of this script is zubro.m
x = 1 + 2;
printf ("%i\n", x);

shell2.sh:

#!/bin/sh
# filename of this script is shell2.sh
echo the result is 

zubro.sh 调用时(确保 chmod u+x 您的脚本...):

$ ./zubro.sh 
the result is 3