Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I used alien to convert an RPM to a .deb. I did NOT use alien's script conversion; I'm converting by hand. Indeed, the script did barf on some non-compatible syntax. My question is NOT about how to fix this incompatibilty, but rather about how the script continues to execute successfully, despite encountering an error.

Here's the problematic section:

if [ "`/bin/echo '\c'`" == "" ]; then
   ECHO_ESC="/bin/echo"
else
   ECHO_ESC="/bin/echo -e"
fi

This causes the following "error":

./avsetup_mcc: 11: [: \c: unexpected operator

Despite this, the script continues to execute perfectly. So, what's happening here?

share|improve this question

1 Answer 1

up vote 2 down vote accepted

[ is not a "special builtin", and according to POSIX a Utility syntax error (option or operand error) of a non-special builtin Shall not exit a non-interactive shell ("script").

So much as for why the shell does not exit. The script functions perfectly because ECHO_ESC is set to something sane no matter how the if branches.

Unlike the error message suggests, the error does not come from the \c but the == which is invalid to use with [ (string equality is tested with a single =), but shells that support [[ (which supports ==) seem to allow == even for the single bracket notation (e.g. bash, ksh). Note that the above code does not error under bash, so you might want to consider retagging your question.

share|improve this answer
    
Ah. Debian uses dash now. Thanks for the great answer. –  chad May 1 '13 at 23:09
    
So . . . are you saying that the else branch still successfully executes, thus setting the value of ECHO_ESC? –  chad May 1 '13 at 23:12
    
Exactly that :-) –  Adrian Frühwirth May 1 '13 at 23:59
    
I'm taking a wild guess regarding where your question is coming from: It is not the if statement itself which fails as [ is not a part of if but a command/builtin on its own, thus the expression evaluates to false and the if executes the else branch "as expected". –  Adrian Frühwirth May 2 '13 at 9:20

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.