Re: login shell?





Thanks for the tips, guys.

The %ENV hash suggestion worked -- I'm actually writing a filter for BBEdit
(OS X) that I also want to work from the command line, and also on IRIX
boxes. Turns out that all CLIs have $ENV{TERM} defined, but within BBEdit
it's not.

But turns out it doesn't matter anyway! I thought BBEdit required "\r"
linebreaks internally, but apparently it translates the "\n"s it gets from
unix filters, so it doesn't matter.

Thanks again.

- B


> On 7/27/05, Bryan R Harris <Bryan_R_Harris@xxxxxxxxxxxx> wrote:
>>
>>
>> Is there a way to determine in perl whether the current script was run from
>> a login shell or not?
>>
>> - B
>>
>>
>
> that depends what you mean by "login shell". You can use $ENV{SHELL}
> to find out what shell, if any, invoked the the current process. You
> can also test if the program has been invoked interactively:
>
> if ( -t STDIN && STDOUT) {
> we're probably interactive
> }
>
> That will return false if the job is being run via cron, but it will
> also return false if there is command line redirection.
>
> The Perl Cookbook has a slightly more complex example in recipe 15.2:
>
> use POSIX qw/getpgrp tcgetpgrp/;
>
> sub am_I_intereactive {
> my $tty;
> open($tty, "<", "/dev/tty")
> or die "can't open /dev/tty: $!";
> my $tpgrp = tcgetpgrp(fileno($tty));
> my $pgrp = getpgrp();
> close $tty;
> return ($tpgrp == $pgrp);
> }
>
> This will tell you if you have control of a tty, which means the
> program was probably invoked from an interactive session, even with
> redirection in place.
>
> What none of this will tell you is whether this is a "login" shell.
> Just because a shell is interactive, that doesn't mean it's a login
> shell. a user can change his/her shell at the command line by typing
> /bin/shell, or using su. In order to really be sure that you were in a
> login shell, you would need to check for interactivity, and then check
> that the parent of the shell that invoked perl was the appropriate
> daemon on your system. And then just for good measure, you'd probably
> want to check the result against the contents of /etc/shell or the
> equivalent on your system to make sure that the shell is a valid login
> shell, and then against the contents of /etc/passwd or equivalent to
> make sure that it is the specified login shell for the current user.
>
> HTH,
>
> -- jay
> --------------------------------------------------
> This email and attachment(s): [ x ] blogable; [ ] ask first; [ ]
> private and confidential
>
> daggerquill [at] gmail [dot] com
> http://www.tuaw.com http://www.dpguru.com http://www.engatiki.org


.



Relevant Pages

  • Re: Where to put shell settings under Suse ?
    ... For runlevel 3, ... page for your shell. ... For a GUI login, your display manager is the login shell, and you should see ... Then xdm runs the Xsession script as the user. ...
    (comp.os.linux.misc)
  • Re: login shell?
    ... that depends what you mean by "login shell". ... The Perl Cookbook has a slightly more complex example in recipe 15.2: ... login shell, you would need to check for interactivity, and then check ...
    (perl.beginners)
  • Re: Issue with the script command in users .kshrc and .bashrc files
    ... One approach is to replace the login shell (in ... Installed-Size: 204 ... Package: pdmenu ...
    (comp.unix.shell)
  • Re: Freeze accounts
    ... Setting their login shell to /bin/false (and later, ... block all account access. ... And traditionally the ftp ...
    (Debian-User)
  • Re: set the environment variable at boot time
    ... and that seems to be where you've stuck your script. ... shell configuration such as /etc/profile. ... Depends on your distribution, and the shell you are using. ... login shell, and with few exceptions, the ...
    (comp.os.linux.misc)