How to know what shell I am ruuning from a C program?

How to know what shell I am ruuning from a C program?

Post by stanislav shalun » Sun, 14 Jan 1996 04:00:00





   I am wondering if there's a way to detect what shell my C program is
   running on from within the C program?

   I know that I can call getenv("SHELL"). However, this doesn't reflect
   what shell I am currently running my program on.(For example, I may
   switch to another shell after I logon...)

Ummm, you don't like SHELL environment variable?  What do you need this
knowledge for?  Usually you are supposed to use $SHELL if you want to run a
subshell or something.  Can you define what you mean?  If you hope your
program was invoked from shell prompt, you might use getppid() and analize
who is your parent, but this is highly platform dependent---on systems that
support accounting it is easier.

--

PGP key fingerprint = 62367EA3D4D01D88E021F40A0D938E12 | public key on www page
Opinions that might have been represented here are just mine, not anyone else's

 
 
 

How to know what shell I am ruuning from a C program?

Post by Yang-Cheng Hsi » Sun, 14 Jan 1996 04:00:00






>   I am wondering if there's a way to detect what shell my C program is
>   running on from within the C program?

>   I know that I can call getenv("SHELL"). However, this doesn't reflect
>   what shell I am currently running my program on.(For example, I may
>   switch to another shell after I logon...)

>Ummm, you don't like SHELL environment variable?  What do you need this
>knowledge for?  Usually you are supposed to use $SHELL if you want to run a
>subshell or something.  Can you define what you mean?  If you hope your
>program was invoked from shell prompt, you might use getppid() and analize
>who is your parent, but this is highly platform dependent---on systems that
>support accounting it is easier.

Hi:

Thank you for the follow-up to my post. The reason why I need to
know this is because that I need to do something from my C program,
and they have to do with the types of shells(csh, ksh, bash) that
my C program is running on. For example, if the my login shell is csh,
and later I probably switch to ksh to run my program under ksh, then
my C program needs to know what type of shell it's on in order to set
the correct informations. But I think that $SHELL can't be an indicator
of what type of shell the program is running on.

So, any advice about this? Please email me. Thanks!

Yang-Cheng

 
 
 

How to know what shell I am ruuning from a C program?

Post by Yang-Cheng Hsi » Sun, 14 Jan 1996 04:00:00


Hi:

I am wondering if there's a way to detect what shell
my C program is running on from within the C program?

I know that I can call getenv("SHELL"). However, this
doesn't reflect what shell I am currently running my
program on.(For example, I may switch to another shell
after I logon...)

Yang-Cheng