1

I am currently trying to find the full directory name of a script I am calling. I found code online that uses:

DIR="$( cd "$( dirname "$( readlink "${BASH_SOURCE[0]}" )" )" && pwd )"

to set the directory, then afterwards, I try to open a file by calling:

open ${DIR}/file_open.jpg

to which I get -bash: /Volumes/Drive: No such file or directory. I am unsure why this doesn't work. I am running it from Mac OSX's terminal. Does anyone have any ideas?

user321627
  • 2,350
  • 4
  • 20
  • 43

1 Answers1

1

Because you didn't quote your variable.

open "${DIR}/file_open.jpg"

You must quote it. See here why quoting is important.

Also DIR is simpler as:

DIR=$(dirname "$(readlink "${BASH_SOURCE[0]}")")
KamilCuk
  • 120,984
  • 8
  • 59
  • 111