Trying to convert script using PUSHD/POPD from BASH to ZSH

615 views Asked by At

I am trying to convert the following script from BASH to ZSH and the POPD just won't work... Could someone help me please?

runMyScript() {
  if [[ -e $PROJECTS_HOME/myFolder/myScript.sh]]; then
    pushd $PROJECTS_HOME/myFolder > dev/null
    . ./myScript.sh
    popd > dev/null
  else
    ... //Do something else instead
  fi
}
runMyScript

The error is this

myScript:popd:5: directory stack empty

Now I know what this means, but I don't seem to be able to fix it... I am also struggling to find a meaningful fix as well.

If I run the script manually, it seems to work fine, but if I run it by calling runMyScript that's when it seems to fail.

Could someone help me out please?

1

There are 1 answers

2
Takuhii On

I altered the script based on some feedback from @shellter and the script now seems to be working... the new code looks like this;

runMyScript() {
  if [ -f "$PROJECTS_HOME"/myFolder/myScript.sh]; then
    pushd "$PROJECTS_HOME"/myFolder
    . ./myScript.sh
    popd
  else
    // CREATE the variables needed to run this script
  fi
}
runMyScript