-1

I am trying to make this script work which was initially written by one of my coworkers for bash shells. The plan is to source it in the zsh shell. As far as I understand it, this script allows to access the helper scripts that are held in this dir across the terminal. However, when I execute just this bit, I keep getting the error message.

I have tried following solutions of some of the already answered questions such as substituting ${BASH_SOURCE[0]} with ${(%):-%N or ${(%):-%x}From here.

PATHNAME="$_";

if [[ "$PATHNAME" != "$0" ]]; then
    export EXAMPLE_DIR=$(dirname $(dirname $(realpath ${BASH_SOURCE[0]})));
else
    >&2 echo "This script should be sourced, not executed in a subshell";
fi

I do not understand why do I keep getting the error and I would really like to understand what is the issue with it. Any help or links for reading extremely appreciated!

  • So your question is how come `$_` and `$0` aren't equal? Could you explain why you thought they *would* be equal? – ruakh Jun 23 '20 at 22:48

1 Answers1

1

zsh is more simple for you case .

if we consider this example , we have file /tmp/test-z , that contains :

#!/bin/zsh
echo '_ => ' $_
echo '0 => ' $0

The value of $0 is always the file , if call or source the file

/tmp/test-z or source /tmp/test-z or . /tmp/test-z or zsh /tmp/test-z

The value of $_ is set to same $0 as the source , so in your case yu can replace ${BASH_SOURCE[0]}) $0 in ZSH

EchoMike444
  • 1,513
  • 1
  • 9
  • 8