Timeline for One-liner to determine the directory of the currently running bash script
Current License: CC BY-SA 4.0
7 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Oct 22, 2018 at 19:29 | comment | added | pjh |
For applications like this, ${BASH_SOURCE[0]} is better than $0 . See choosing between $0 and BASH_SOURCE.
|
|
Oct 22, 2018 at 19:20 | comment | added | pjh |
See How to check if a program exists from a Bash script? for information about problems with which , and what to use instead.
|
|
Oct 22, 2018 at 11:41 | history | edited | Bsquare ℬℬ | CC BY-SA 4.0 |
added 1934 characters in body
|
Oct 22, 2018 at 11:36 | comment | added | Bsquare ℬℬ | I guess my first answer was ambiguous, I edited it to give you complete explanation, with a working sample. Hoping it reaches your needs. | |
Oct 22, 2018 at 11:35 | history | edited | Bsquare ℬℬ | CC BY-SA 4.0 |
added 1934 characters in body
|
Oct 22, 2018 at 11:13 | comment | added | nagylzs | Well, if we don't care abount symbolic links, then a simple dirname $0 will do. But I need to care, and in that case, your code will certainly fail. The which command cannot be used, please read the question again. These scripts must be location independent, and they may not be on PATH at all. (Only some symlinks to some of them) | |
Oct 22, 2018 at 10:06 | history | answered | Bsquare ℬℬ | CC BY-SA 4.0 |