[ACCEPTED]-OS X bash: dirname-dirname
What about:
cd "$(dirname "$0")"
That works for me here.
0
#!/bin/sh
cd "$(dirname "$0")"
0
What finally worked for me is changing this:
#!/bin/sh
cd `dirname $0`
To 3 this:
#! /bin/zsh
cd "${0:h}"
This also supports file names and file 2 paths containing spaces. Here's where I 1 found it: http://rentzsch.com/unix/locationAwareCommandFiles
Escaping the inner double quotes is unnecessary:
cd "`dirname "$0"`"
But 7 that doesn't get to the root of the problem, which 6 is that somehow the value of $0 appears 5 to be empty, or perhaps something strange. Try 4 changing running your script this way:
bash -x scriptname
This 3 will echo each line, with variables interpolated, before 2 running it. It is very useful for debugging. Also 1 quite helpful are:
-u: abort on attempt to use undefined variable
-e: abort on first error
Hey not sure about this... But is it possible 3 that your
#!/bin/sh
Points to something that is not 2 bash? What I usually use is:
#!/usr/bin/bash
Pretty new 1 to the whole scripting thing so not sure.
More Related questions
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.