I have a C++ application that needs to make shell specific commands using system calls. Is there a way to detect which shell the user is running? (Csh/Bash/etc).
Thanks
Elaborate
I'm trying to work with some code that forks off via system a rsh call that has a sequence of commands that are using setenv which doesnt work in bash. I want to detect whether the system is csh or bash and rewrite the calls accordingly.
Get the userid with geteuid, get the user database entry for that ID getpwuid containing the shell and must not be freed. So it breaks down to
getpwuid(geteuid())->pw_shell
Minimal working example:
#include <pwd.h>
#include <unistd.h>
#include <stdio.h>
int main (int argc, const char* argv[]) {
printf("%s\n", getpwuid(geteuid())->pw_shell);
return 0;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With