Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

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: line 135: [: missing `]' 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

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
If you do have spaces, use "$BP" instead (wrap in quotes). – Scott Wilson Apr 6 '12 at 16:42

Your Answer


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.