1

I have a bash script that will need to be executed using the bash built-in source. But it needs to read its own filename and update PATH based on it. Unfortunately, $0 does not contain the name of the script. So the following does not work.

ABSDIR=$(pwd)/$(dirname "$0")
export PATH="$ABSDIR/Library/Developer/CommandLineTools/usr/bin:$PATH"

Is there a way to get the name of the script file in this context?

source ~/CLTools/Clang-5.0/activate

1 Answer 1

2

Take a look at:

echo ${BASH_SOURCE[0]}
Sign up to request clarification or add additional context in comments.

1 Comment

What do you mean with "take a look"? Try to expand the answer to make it something more than a comment.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.