Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/unix/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Shell 从命令行运行多个倍频程脚本_Shell_Unix_Process_Octave - Fatal编程技术网

Shell 从命令行运行多个倍频程脚本

Shell 从命令行运行多个倍频程脚本,shell,unix,process,octave,Shell,Unix,Process,Octave,我有多个八度脚本,需要按顺序执行。第二个脚本依赖于第一个脚本,因此它必须等待第一个脚本完成。我还想从命令行传入两个参数。但是,下面的脚本在执行第二个脚本之前并不等待第一个脚本。我怎样才能纠正这个问题 EXP_ID = $1; NUM_FEATURES = $2; cd fisher; octave computeFisherScore-AG.m $EXP_ID; cd ..; octave predictability-AG.m $EXP_ID $NUM_FEATURES; 尝试:

我有多个八度脚本,需要按顺序执行。第二个脚本依赖于第一个脚本,因此它必须等待第一个脚本完成。我还想从命令行传入两个参数。但是,下面的脚本在执行第二个脚本之前并不等待第一个脚本。我怎样才能纠正这个问题

EXP_ID = $1;    
NUM_FEATURES = $2;

cd fisher;
octave computeFisherScore-AG.m $EXP_ID;
cd ..;
octave predictability-AG.m $EXP_ID $NUM_FEATURES;
尝试:


查看

也许您的八度音阶脚本是在后台运行的。您可以使用以下解决方法:

waitpid() {
    while kill -s 0 "$1" >/dev/null 2>&1; do
        sleep 1
    done
}

cd fisher;
octave computeFisherScore-AG.m $EXP_ID;
waitpid "$!"
cd ..;
octave predictability-AG.m $EXP_ID $NUM_FEATURES;
我还建议您正确引用您的参数,以防止意外的分词和路径名扩展:

cd fisher
octave computeFisherScore-AG.m "$EXP_ID"
waitpid "$!"
cd ..
octave predictability-AG.m $EXP_ID "$NUM_FEATURES"

分号也可能不是必需的。

是否单独运行这些脚本?为什么要编写一个按顺序调用八度脚本的bash脚本?为什么不只是一个同时运行这两种语言的八度脚本呢?还有,你为什么不使用
#制作一个八度音阶脚本呢!bin/octave
作为shebang行,并授予它执行权限?我同意@carandraug,没有必要单独运行两个octave脚本或依赖Shell脚本。重构你的代码或创建另一个八度脚本,按顺序调用另外两个。我理解你的意思。在这种情况下,由于本问题范围之外的原因,它们需要是单独的脚本,并且通常是独立运行的。谢谢!我需要仔细研究一下,看看这是否能解决问题!非常感谢。我也需要好好玩玩,看看这能不能解决问题!字符串拆分肯定也是一个问题,请您考虑报价建议。这绝对是其中的一部分。@Adam_G Ok。我仍然很好奇,为什么您的原始脚本不能用于
倍频程
。它不能自己在后台运行。但是
wait
可以使用它。
cd fisher
octave computeFisherScore-AG.m "$EXP_ID"
waitpid "$!"
cd ..
octave predictability-AG.m $EXP_ID "$NUM_FEATURES"