Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm writing a bash script which I'm testing on OS X though it will ultimately run on a standard Linux environment and running into a weird error.

I have tests like this in my script:

if [ ! -w $BP ]; then
  echo "'$1' not writable"
  exit 1
fi

Which seems pretty sane to me and works fine under Linux but when trying to test on OS X I get the following error message:

startSvr.sh: line 135: [: missing `]' startSvr.sh: line 135: -w: command not found

So is this a case of OS X not supporting the -w test or is there some other reason this isn't working for me? e.g. environment

share|improve this question
add comment

1 Answer

Is it possible you don't have a space after the filename, i.e. the line is actually

if [ ! -w $BP]; then

because that would generate the error you see.


Updated after OP indicated directory name could include spaces

Suggest changing your code to

if [ ! -w "$BP" ]; then
share|improve this answer
    
Not sure if this is the exact cause of the problem because the scripts do have the space but it seems some paths cause the problem and some don't likely because of spaces or similar in the path –  RobV Apr 6 '12 at 16:41
    
Having spaces in directory names in *nix is a great way to cause yourself grief. Suggest you switch to underscores or something else. –  Scott Wilson Apr 6 '12 at 16:42
1  
If you do have spaces, use "$BP" instead (wrap in quotes). –  Scott Wilson Apr 6 '12 at 16:42
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.