in reply to How do I test if my Perl script was run using a login vs a non-login shell
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.
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.
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.
Aaron B.
Available for small or large Perl jobs; see my home node.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: How do I test if my Perl script was run using a login vs a non-login shell
by paulski82 (Novice) on May 23, 2012 at 04:39 UTC | |
by aaron_baugher (Curate) on May 23, 2012 at 12:46 UTC | |
by Anonymous Monk on May 23, 2012 at 06:04 UTC | |
by paulski82 (Novice) on May 23, 2012 at 08:07 UTC | |
by Anonymous Monk on May 23, 2012 at 12:20 UTC |