Open demurgos opened 3 years ago
Ok, I think it's reasonable.
Thanks for the feedback, I'll look into sending a PR in this case.
While prototyping it in my main project, I also found that it would be useful to support not only sh
but other POSIX utilities but it does not change much from the implementation point of view.
Hi! I am writing a Rust program that installs a POSIX shell script. In order to configure the shebang line properly, I would like to follow the spec and resolve the absolute
sh
path.https://pubs.opengroup.org/onlinepubs/9699919799/utilities/sh.html#tag_20_117_16
This behavior is close enough to
which
(but not quite the same) that I feel that this crate would be the best place to implement it. I propose adding aposix_sh
function returning the absolute path to the posix shell found this way. The main difference is that the resolution should not use thePATH
environment variable but use thegetconf
function to retrievePATH
(so it is not subject to user-made changes to thePATH
variable, for example in a situation where the process is spawned without environment variables).This difference in behavior is slightly subtle, having this logic built-in here would make it easier for other devs to discover and use.
I am willing to send a PR for this feature if it is OK.
Regarding the implementation, I'd use a platform check to enable this function only on platforms supporting
getconf
.