Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place. |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
02-24-2002, 05:10 AM
|
#1
|
Member
Registered: Feb 2002
Distribution: Debian / Debian-based
Posts: 58
Rep:
|
Difference between normal shell and login shell
What is the difference between running a shell (e.g. bash) as a normal shell VS as a login shell (with the option -login, or prefixing hyphen to its sym. link) ??
Thanks.
|
|
|
03-09-2002, 02:17 PM
|
#2
|
LQ Guru
Registered: Jan 2001
Posts: 24,149
|
I don't understand your question. I thought a shell was a shell, either using bash, sh, csh, tcsh... etc etc... logging in or already logged in..
-trickykid
|
|
|
03-09-2002, 03:25 PM
|
#3
|
root 
Registered: Jun 2000
Distribution: Debian, Red Hat, Slackware, Fedora, Ubuntu
Posts: 13,618
|
You can invoke bash as a login shell or as an interactive shell. From the man page:
Quote:
A login shell is one whose first character of argument zero is a -, or one started with the -login flag.
An interactive shell is one whose standard input and output are both connected to terminals (as determined by
isatty(3)), or one started with the -i option. PS1 is set and $- includes i if bash is interactive, allowing a
shell script or a startup file to test this state.
Login shells:
On login (subject to the -noprofile option):
if /etc/profile exists, source it.
if ~/.bash_profile exists, source it,
else if ~/.bash_login exists, source it,
else if ~/.profile exists, source it.
On exit:
if ~/.bash_logout exists, source it.
Non-login interactive shells:
On startup (subject to the -norc and -rcfile options):
if ~/.bashrc exists, source it.
Non-interactive shells:
On startup:
if the environment variable ENV is non-null, expand
it and source the file it names, as if the command
if [ "$ENV" ]; then . $ENV; fi
had been executed, but do not use PATH to search
for the pathname. When not started in Posix mode, bash
looks for BASH_ENV before ENV.
If Bash is invoked as sh, it tries to mimic the behavior of sh as closely as possible. For a login shell, it
attempts to source only /etc/profile and ~/.profile, in that order. The -noprofile option may still be used to
disable this behavior. A shell invoked as sh does not attempt to source any other startup files.
|
--jeremy
|
|
|
03-09-2002, 10:02 PM
|
#4
|
Member
Registered: Feb 2002
Distribution: Debian / Debian-based
Posts: 58
Original Poster
Rep:
|
Thanks jeremy. 
|
|
|
11-13-2012, 06:58 PM
|
#5
|
LQ Newbie
Registered: Sep 2004
Location: sili vali
Distribution: mostly Suse, try to use others too
Posts: 5
Rep:
|
I didn't understand the docs either
Login shell is the first one you run when you 'log in': when you sign in on a SSH session, or add a new terminal emulator window or tab. To check:
$ echo $0
-bash
$ ps
456 ttys006 0:00.22 -bash
459 ttys007 0:03.81 bash
1633 ttys008 0:00.03 bash
10935 ttys009 0:00.07 -bash
-bash = login shell, bash = not login. processes 456 and 10935 are login shells.
Interactive shell is when you type in 'bash' from your login or another interactive shell. and stdin and stdout are terminals.To see if yours are terminals (they probably are if you're typing in), run these:
$ [ -t 0 ] && echo stdin is a tty
$ [ -t 1 ] && echo stdout is a tty
The $- env var tells you what options your shell runs in. i=interactive. for example:
$ echo $-
himBH
that one had stdin=terminal, this one has a pipe as stdin:
$ echo 'echo $-' | bash
hB
Login shell runs .profile (or .bash_profile or .bash_login) on startup. Set your env variables in there, cuz sub-shells will inherit the env vars. Then make .profile run your .bashrc:
. .bashrc
Interactive runs .bashrc . Since it inherits envs, but not aliases, put your aliases in this file.
Shell scripts, cron jobs, and the like, run with a bare shell: no bashrc or profiles are run. No kidding you get 4 env vars set, the bare minimum. Therefore your PATH won't work very well so you often have to give an abs pathname like in crontab:
right: 0 0 * * 2 /usr/sbin/apachectl restart
wrong: 0 0 * * 2 apachectl restart
|
|
|
11-14-2012, 08:11 AM
|
#6
|
Member
Registered: Oct 2012
Distribution: OpenSuSE,RHEL,Fedora,OpenBSD
Posts: 982
|
> whose first character of argument zero is a -
That will make most sense to C programmers who know the variable argv[] as given to the main() function.
|
|
|
11-14-2012, 08:29 AM
|
#7
|
LQ Guru
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 11,136
|
This option is used to tell Bash how it's supposed to behave. When you log in successfully, getty execs the specified shell-program to give you the command prompt. This shell instance (which replaces "getty") will be the root of all other processes in your session, and as such it needs to look and behave a little differently.
|
|
|
11-14-2012, 08:30 AM
|
#8
|
Member
Registered: Oct 2012
Distribution: OpenSuSE,RHEL,Fedora,OpenBSD
Posts: 982
|
Quote:
Originally Posted by sundialsvcs
This option is used to tell Bash how it's supposed to behave. When you log in successfully, getty execs the specified shell-program to give you the command prompt. This shell instance (which replaces "getty") will be the root of all other processes in your session, and as such it needs to look and behave a little differently.
|
getty to login to -shell
|
|
|
All times are GMT -5. The time now is 03:21 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|