【问题标题】:Octave parse variable to shell scriptOctave 解析变量到 shell 脚本
【发布时间】:2017-09-27 14:23:54
【问题描述】:

我有由不同脚本组成的 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

【问题讨论】:

  • @Andy 我已经通过基本示例更改了整个代码
  • 好的,有几种方法。我会让 octave 脚本像其他 unix 实用程序一样将结果打印到标准输出,并在 bash 中读回它。另一种(脏?)方法是使用 Octave 脚本中的 setenv。另一个写入临时文件并读回
  • 为什么不使用 GNU Octave 来循环输入文件?如果速度很重要,这会更快
  • @Andy 感谢您的回复。 GNU Octave 是什么意思?

标签: shell parsing ubuntu octave


【解决方案1】:

正如我在评论中已经说过的:让 GNU Octave 在标准输出上返回值:

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 $1

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

$ ./zubro.sh 
the result is 3

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-08
    • 2011-02-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多