How to get the script's own path in sourced Bash script?

In normal Bash script, $0 is the path to the script. However, when a script is sourced, such as

.'s $0 does not give How to get the inside

asked Feb 10, 2016 by anonymous

1 Answer

Short answer: use ${BASH_SOURCE[0]}.

You can check this post for details and explanations: How to Get Bash Script’s Own Path.

answered Feb 13, 2016 by Eric Z Ma (44,280 points)
edited Feb 13, 2016 by Eric Z Ma

Please log in or register to answer this question.

Copyright © SysTutorials. User contributions licensed under cc-wiki with attribution required.
Hosted on Dreamhost