It is possible to fool $ENV{SHELL} into thinking it's something other than the right answer. So I was going to mention using Proc::ProcessTable or something, combined with $$, to see what your parent process was, and check what that command was, etc., until you found a shell. But two things stop me from actually suggesting it. First, your program may be run from another program from another from the cron daemon, which is owned by init. So there may not be an obvious shell (it's there, but you may not be able to easily find it). Or your parent process may have died, and you got inherited by init.

So, I second the vote on $ENV{SHELL}. If some advanced user wants to fool you into thinking the shell is csh when it's really bash, well, they may actually know what they're doing. Let them. If it's not set, ask that it be set - or have a reasonable fallback, whatever that means to your program.

Although, I have to admit some curiosity - what are you doing that you care what the shell is? The only thing I can think of is that you're printing out a bunch of environment-setting commands, and you want to know whether to "setenv" or "export" them so that a parent shell could say exec `set_env.pl`.


In reply to Re: find the shell inside a perl script by Tanktalus
in thread find the shell inside a perl script by jesuashok

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.