You are not logged in.

#1 2007-04-30 15:14:08

chicha
Member
From: France
Registered: 2007-04-20
Posts: 271

How to identify if I am using a login shell or not ?

Hello all,

I can identify if I am in an interactive shell by checking for an occurance of 'i' in the variable '$-'.
I already know how to invoke an interactive login shell (bash --login for instance).
Let's say that I use a shell and I do not know how it was invoked ...
The question is how can I identify if I am in a login shell ?

Thank you for your help smile
Cheers,
Chicha

Offline

#2 2007-04-30 19:38:32

.:B:.
Forum Fellow
Registered: 2006-11-26
Posts: 5,819
Website

Re: How to identify if I am using a login shell or not ?

Quite easy... Any login shell will ask you for a username and password. Otherwise, it wouldn't be a login shell...


Got Leenucks? :: Arch: Power in simplicity :: Get Counted! Registered Linux User #392717 :: Blog thingy

Offline

#3 2007-05-01 08:43:30

chicha
Member
From: France
Registered: 2007-04-20
Posts: 271

Re: How to identify if I am using a login shell or not ?

Thank you B for your help smile
But the exact question is :

chicha wrote:

Let's say that I use a shell and I do not know how it was invoked ...

Anyway I found a workaround :

echo $0

This will display 'bash' (or zsh, csh ...) in an interactive non-login shell and '-bash' (or -zsh ...) in an interactive login shell (notice the minus in front of the shell name).

I do not know if there is another way to find this information...
Cheers
Chicha

Offline

#4 2007-05-01 14:22:42

Borosai
Member
From: Sandy Appendix, U.S.A.
Registered: 2006-06-15
Posts: 227

Re: How to identify if I am using a login shell or not ?

This is taken from the zsh user guide. I guess it's not the most practical solution, but it works.

if [[ -o login ]]; then
    print yes
  else
    print no
  fi

Offline

#5 2007-05-02 08:56:57

chicha
Member
From: France
Registered: 2007-04-20
Posts: 271

Re: How to identify if I am using a login shell or not ?

Thank you Borosai smile
This work very well for zsh and is exactly what I am looking for.
Any idea about how to do this with bash (the login option does not exist) ?

Offline

#6 2007-05-02 14:04:16

Borosai
Member
From: Sandy Appendix, U.S.A.
Registered: 2006-06-15
Posts: 227

Re: How to identify if I am using a login shell or not ?

I have no idea about bash...sorry.

Offline

#7 2007-05-02 14:23:04

chicha
Member
From: France
Registered: 2007-04-20
Posts: 271

Re: How to identify if I am using a login shell or not ?

No problem smile
You gave me a good trick anyway !
Cheers,
Charles-Henri

Offline

Board footer

Powered by FluxBB