The variable $^X contains the name of the Perl executable, and perlvar says it comes from C's argv[0], so that seems like it should be the answer. It doesn't seem to include the hyphen like it does in C for some reason, though.

I did search the perlvar man pages and noted the same as you that $^X doesn't have the starting '-'. I'm beginning to think that Perl is not the language to be writing a shell in. I could write the C code but it's way harder to manage.

As an aside, on FreeBSD I do get the hyphen (in C) in a login shell and not otherwise, but I get "su" and "-su" instead of the name of the shell like you get in Linux. So the hyphen part may be portable, but it doesn't look like the rest is.

As long as I can get the '-' I can fudge the rest.

One option would be to look for an environment variable that's set in a login shell and not otherwise. Hard to say how portable that would be, though. It's pretty hard to make anything universally portable when you're talking about the shell, since there are so many different ones, even on the same OS.

My script will be the shell so I'm not sure of any variable that's going to be reliable. Unless when Perl is called it runs under a shell itself and I can make the decision based on the shell Perl runs under. That may be good enough.

I may have to do a hack like:

If bash and VAR1 is set assume login OR If ksh and VAR2 is set assume login.

But that's kinda ugly and I may just end up writing the whole shell in C.


In reply to Re^2: How do I test if my Perl script was run using a login vs a non-login shell by paulski82
in thread How do I test if my Perl script was run using a login vs a non-login shell by paulski82

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.