3 comments on “Bash script: PWD vs true script location, with symlinks

  1. so, as you might imagine, $0 is argv[0], which means that it is set by the calling process’s exec* call.

    *convention* is that argv[0] is the name of the script, but it’s not necessarily. you can easily change $0 of a script by calling it with execv or something differently. in fact, the way busybox works is it’s this massive single binary that chooses its behavior based on what argv[0] is.

    what you’re probably most interested in is $BASH_SOURCE, which is the file bash loaded to run.

    anyway, in practice it will never matter. argv[0] is hardly ever changed, so, probably doesn’t matter. hth

Leave a Reply to Matthew Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.