0

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

1

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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