Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Running "unset path" breaks PATH despite emulation being enabled



On Sep 9,  3:38pm, Eric Pruitt wrote:
}
} What want is for Z shell to return is the name to the invoked
} interpreter which is what $BASH shows even when $PATH doesn't contain
} Bash.

OK, that's just a little bit trickier.  Here's script equivalent of the 
actual heuristic Bash uses:

  # Set $ZSH the way Bash sets $BASH
  get_ZSH() {
    emulate -L zsh
    if [[ -o login && $ZSH_ARGZERO != /* ]]
    then ZSH=$SHELL
    elif [[ $ZSH_ARGZERO = /* ]]
    then ZSH=$ZSH_ARGZERO
    elif [[ $ZSH_ARGZERO = ./* ]]
    then ZSH=$ZSH_ARGZERO:P
    else
      local -a tname=( $^path/$ZSH_ARGZERO(N[1]) )
      if [[ -z $tname ]]
      then
        if [[ -x $ZSH_ARGZERO ]]
        then ZSH=$ZSH_ARGZERO:P
        else ZSH=$SHELL
        fi
      else
        ZSH=$tname:P
      fi
    fi
  }

This only works if it's executed before any chdir has been done.

For older zsh that don't have the :P modifier, use :A.



Messages sorted by: Reverse Date, Date, Thread, Author