在shell脚本语法错误说意外的标记'( [英] Syntax error in shell script saying unexpected token `(

查看:1218
本文介绍了在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

这篇关于在shell脚本语法错误说意外的标记'(的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆