|
|
|
|
|
by iainmerrick
660 days ago
|
|
It's huge to be able to have a pointer to the directory where the executable resides, so you can package other assets along side it and have it all work for free without a seperate configuration file or env variables etc. Yes! I was surprised how far down I had to scroll to find somebody mentioning that one. How else can you write a reasonably robust script that actually, you know, does something? You almost always need to grab some known files by their paths relative to the script. |
|
Some languages don't provide a better solution but they should. For Bash there is ${BASH_SOURCE[0]}. For compiled executables you use OS-provided functions like GetModuleFileName(NULL, ...) on Windows and readlink("/proc/self/exe", ...) on Linux.