views:

38

answers:

3

I have this run as a Shell Script target in my Xcode project

# shell script goes here
genstrings -u -a -o en.lproj *[hmc] */*[hmc] */*/*[hmc]
if [ -f "$PROJECT_DIR/build/Release-macosx/UnicodeEscape" ] then
    build/Release-macosx/UnicodeEscape "en.lproj/Localizable.strings"
elif [ -f "$PROJECT_DIR/build/Debug-macosx/UnicodeEscape" ] then
    build/Debug-macosx/UnicodeEscape "en.lproj/Localizable.strings"
fi

exit 0

I get this error:

/Users/aa/Dropbox/Developer/Pandamonia LLC/iPhone/Acey Deucey/build/Acey Deucey.build/Release/GenerateLocalizedStrings.build/Script-00F66869125625D9009F14DA.sh: line 7: syntax error near unexpected token elif' /Users/aa/Dropbox/Developer/Pandamonia LLC/iPhone/Acey Deucey/build/Acey Deucey.build/Release/GenerateLocalizedStrings.build/Script-00F66869125625D9009F14DA.sh: line 7:elif [ -f "$PROJECT_DIR/build/Debug-macosx/UnicodeEscape" ] then' Command /bin/sh failed with exit code 2

+4  A: 

First of all, do not tag it bash and sh, you have one shell, type echo $SHELL to know which shell you use, or put a shebang at the start of your script (#!/usr/bin/env bash)

put semicolons after your commands, including [ ... ] which is an alias for test. Command terminators are newline, ;, &&, || and & and are mandatory. You can put several commands between if and then, so those semicolons are mandatory.

if [ -f "$PROJECT_DIR/build/Release-macosx/UnicodeEscape" ] ; then
    build/Release-macosx/UnicodeEscape "en.lproj/Localizable.strings" ;
elif [ -f "$PROJECT_DIR/build/Debug-macosx/UnicodeEscape" ] ; then
    build/Debug-macosx/UnicodeEscape "en.lproj/Localizable.strings" ;
fi
Benoit
+3  A: 

The then statement needs to be on a new line, or separate from the if condition with ;.

Douglas Leeder
+2  A: 

You need semicolons before the keyword then .

# shell script goes here
genstrings -u -a -o en.lproj *[hmc] */*[hmc] */*/*[hmc]
if [ -f "$PROJECT_DIR/build/Release-macosx/UnicodeEscape" ]; then
    build/Release-macosx/UnicodeEscape "en.lproj/Localizable.strings"
elif [ -f "$PROJECT_DIR/build/Debug-macosx/UnicodeEscape" ]; then
    build/Debug-macosx/UnicodeEscape "en.lproj/Localizable.strings"
fi

exit 0
Yuji