Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Allow .command files to determine working directory' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Allow .command files to determine working directory
Authored by: kholburn on Dec 21, '04 09:51:53AM
dirname is a program so running `dirname $0` runs another program (which should be there). There is a way to do it using just bash.

#!/bin/sh
dir=${0%/*}
if [ "$dir" = "$0" ]; then
  dir="."
fi
cd "$dir"


or

#!/bin/sh
dir=${0%/*}
if [ -d "$dir" ]; then
  cd "$dir"
fi


[ Reply to This | # ]