在shell脚本语法错误说意外的标记'(

在shell脚本语法错误说意外的标记'(

问题描述:

我写了下面的shell脚本

I have written the following shell script

while :; do
status=$($EMR_BIN/elastic-mapreduce --jobflow $JOBFLOW --list | grep "CopyLogs" | awk '{print $1}')
[[ $status == +( *RUNNING*|*PENDING*|*WAITING* ) ]] || break
sleep 60
done

它给我一个错误在第3行话说语法错误在条件前pression:意外的标记(''我试图给我的括号之间的空格,但它不工作。

Its giving me an error in line 3 saying syntax error in conditional expression: unexpected token('' . I tried giving whitespaces between my braces, but its not working.

任何人都可以帮助我。

看起来你要使用扩展通配。请确保您有禁用了javascript -s extglob 在你的脚本前面的某个地方,或重写使用标准的通配。

Looks like you are trying to use extended globbing. Make sure you have shopt -s extglob somewhere earlier in your script, or rewrite to use standard globbing.

#!/bin/sh
while :; do
    case $($EMR_BIN/elastic-mapreduce --jobflow $JOBFLOW --list | awk '/CopyLogs/{print $1}') in
        *RUNNING*|*PENDING*|*WAITING* ) sleep 60;; 
        *) break;;
    esac
done

由于没有剩余bash化,这个脚本是现在POSIX SH 兼容。 (个人而言,我也觉得是更具可读性这种方式)。

Since there are no remaining Bashisms, this script is now POSIX sh compatible. (Personally, I also think it is more readable this way.)

(注还修复了没用的grep |。AWK