diff --git a/set_env.sh b/set_env.sh
index dac69717f4205cd6a58020ef1e88ebcc34bc6de2..c60d173bf1cdf2cf86e4193edb1b9b50264b4b32 100755
--- a/set_env.sh
+++ b/set_env.sh
@@ -24,7 +24,7 @@ if [ -z $DESIGN_ROOT ]; then
     source $DESIGN_ROOT/set_env.sh
 else
     # Set Environment Variable for this Repository
-    export CHIPKIT_DIR="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
+    export CHIPKIT_DIR="$(cd -P "$(dirname "${BASH_SOURCE[0]:-${(%):-%x}}")" && pwd)"
 
     # If this Repo is root of workspace
     if [ $CHIPKIT_DIR = $DESIGN_ROOT ]; then