Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

an excerpt of a startup script looks like this:

ENABLED=1

test "$ENABLED" != "0" || exit 0

The problem is, no matter if Enabled is set to 0 or 1, the script always exits at that line. I looked up "man test" and as far as I understand it, test will always evaluate the expression and then exit(!!) with the return code? Is this correct. So This script will, at this line, always exit no matter what the value of the variable is? (so its buggy).

thanks!! jens

share|improve this question
    
Is this supposed to be Perl or bash? –  Ignacio Vazquez-Abrams Nov 3 '10 at 5:32
    
Hello Ignacio,thanks for your anser. Uh well I actually do not konw (I am no expert in this). Its a default Debian Lenny installation and the script is a startscript of a package that I installed. The Script starts with #!/bin/sh –  jens Nov 3 '10 at 5:35
add comment

2 Answers

up vote 3 down vote accepted
#!/bin/bash
ENABLED=1
test "$ENABLED" != "0" || exit 0
echo "wasn't zero"

when i run this, i get

[madhatter@risby tmp]$ ./foo
wasn't zero

So, it seems to me that either

  • you're using an odd interpreter (which shell are you running this under), or
  • you're picking up the wrong `test` (could you do a `which test` and tell us the results, or explicitly use `/usr/bin/test`?), or
  • (sorry about this) you're wrong about it not getting to the next line (as Janne says above, could we see more of the shell script, or could you put a one-line canary like my echo statement immediately after the test?
share|improve this answer
add comment

That test statement basically says "exit with return code 0 (which usually means OK in this wonderful world of Linux/Unix) if $ENABLED is set to something else than 0".

Did this clarify you at all? It's hard to tell you more without seeing the complete start-up script :-)

share|improve this answer
add comment

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.