0

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

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.

Can anyone help me out.

Some programmer dude
  • 400,186
  • 35
  • 402
  • 621
user2890683
  • 403
  • 2
  • 6
  • 18
  • You have to use "=~" operator instead of "==". http://stackoverflow.com/questions/304864/how-do-i-use-regular-expressions-in-bash-scripts – spinus May 25 '14 at 09:30

1 Answers1

1

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

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

(Note also the fix for the useless grep | awk.)

tripleee
  • 175,061
  • 34
  • 275
  • 318