Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Find POSIX shell #38

Open
demurgos opened this issue May 12, 2021 · 2 comments
Open

Find POSIX shell #38

demurgos opened this issue May 12, 2021 · 2 comments

Comments

@demurgos
Copy link

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

Furthermore, on systems that support executable scripts (the "#!" construct), it is recommended that applications using executable scripts install them using getconf PATH to determine the shell pathname and update the "#!" script appropriately as it is being installed (for example, with sed).

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 a posix_sh function returning the absolute path to the posix shell found this way.
The main difference is that the resolution should not use the PATH environment variable but use the getconf function to retrieve PATH (so it is not subject to user-made changes to the PATH 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.

@harryfei
Copy link
Owner

Ok, I think it's reasonable.

@demurgos
Copy link
Author

demurgos commented May 12, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants