3 ms·
I have always thought that shebangs are absolute paths to be weird. Everything else in my Linux day to day operates by traversing the PATH, why do shebangs get
by fbdab103 3y ago
I have always thought that shebangs are absolute paths to be weird. Everything else in my Linux day to day operates by traversing the PATH, why do shebangs get to be different?
- knome 3y agothe PATH search is done in userspace by the exec'ing process. the kernel doesn't have or care what the processes' environment PATH says. it just gets the final location. shebang processing is the kernel peeking at the first couple hundred bytes of a file to see if it should execute it using some other file instead of running it directly. there isn't a userspace yet because it's still setting the process up. even if there was a userspace, PATH searching should be done for the `exec`ing process' path, not the PATH given to the new process. so you'd have to squirrel away the calling processes path somewhere on top of everything else. so, it would be a pain. and also incompatible with all of the previous exec system calls, since if you "fixed" it to follow the path, anything not expecting that could break.