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