シェルスクリプトファイルの配置されたディレクトリを取得する方法(bash)
他に良い方法無いのかなぁ?
1.準備
# pwd
/tmp/testdir
# cat test.sh
cd `echo "$0" | /bin/sed -e s/"$(basename $0)"//`
SHELL_HOME=`/bin/pwd`
echo $SHELL_HOME
2.カレントディレクトリで実行
# ./test.sh
/tmp/testdir
3.絶対パスで実行
# pwd
/etc
# /tmp/testdir/test.sh
/tmp/testdir
4.相対パスで実行
# pwd
/etc/init.d
# ../../tmp/testdir/test.sh
/tmp/testdir