#!/bin/zsh call=$0 real=$call die() { echo "$*" >/dev/stderr exit 1 } while [ -L "$real" ]; do real="$(stat -c %N "$real" |sed -r "s:..*. -> .(.*).$:\1:")" done _EXEC="$(dirname "$real")" #execution directory _STOR="$(dirname "$call")" #storage directory [ -w "$_EXEC" ] && [ -d "$_EXEC" ] || die "storage directory must be writable" echo ex: $_EXEC echo st: $_STOR