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.
Advertisement
Answer
Dont know if this will be of any use
JavaScript
x
#include <iostream>
#include <cstdlib> /* getenv */
int main ()
{
char* Shell;
Shell = getenv ("SHELL");
if (Shell!=NULL)
std::cout << Shell << std::endl;
return 0;
}
Will output something similar to
JavaScript
/bin/bash
Getenv returns a c-string with the environment variables value.