Re:Why bother with argv[0]?
by teddyh on Tuesday September 03, 2024 @12:49PM
(#41436728)
Surely you mean
[ Parent
| on HN ]
Re:Why bother with argv[0]?
by oguz-ismail on Tuesday September 03, 2024 @12:53PM
(#41436762)
`#!/bin/sh' makes this less portable than it could be, if /bin/sh doesn't exists on my system it won't work, for example. Remove that line and it'll work everywhere.
If /bin/sh does not exist, what in the world is executing the shell script?
Re:Why bother with argv[0]?
by oguz-ismail on Tuesday September 03, 2024 @01:08PM
(#41436935)
The shell, of course. It just might not be (because it doesn't have to be) located in /bin.
I’m pretty sure that /bin/sh is mandated by POSIX.
Re:Why bother with argv[0]?
by oguz-ismail on Tuesday September 03, 2024 @01:45PM
(#41437258)
It's not. See https://pubs.opengroup.org/onlinepubs/9799919799/utilities/s...
Applications should note that the standard PATH to the shell cannot be assumed to be either /bin/sh or /usr/bin/sh, and should be determined by interrogation of the PATH returned by getconf PATH, ensuring that the returned pathname is an absolute pathname and not a shell built-in.