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 Answer 1

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .