diff --git a/set_env.sh b/set_env.sh
index 9c06f622e32ded100d95fe919f16c829b2aa1362..c03ff1342ecb77c723f0ed1e7de32d1f1287e4ec 100644
--- 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 NANOSOC_DIR="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
+    export NANOSOC_DIR="$(cd -P "$(dirname "${BASH_SOURCE[0]:-${(%):-%x}}")" && pwd)"
 
     # If this Repo is root of workspace
     if [ $NANOSOC_DIR = $DESIGN_ROOT ]; then