LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
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


Reply
  Search this Thread
Old 02-24-2002, 05:10 AM   #1
Manish
Member
 
Registered: Feb 2002
Distribution: Debian / Debian-based
Posts: 58

Rep: Reputation: 15
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.
 
Old 03-09-2002, 02:17 PM   #2
trickykid
LQ Guru
 
Registered: Jan 2001
Posts: 24,149

Rep: Reputation: 269Reputation: 269Reputation: 269
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
 
Old 03-09-2002, 03:25 PM   #3
jeremy
root
 
Registered: Jun 2000
Distribution: Debian, Red Hat, Slackware, Fedora, Ubuntu
Posts: 13,602

Rep: Reputation: 4084Reputation: 4084Reputation: 4084Reputation: 4084Reputation: 4084Reputation: 4084Reputation: 4084Reputation: 4084Reputation: 4084Reputation: 4084Reputation: 4084
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
 
Old 03-09-2002, 10:02 PM   #4
Manish
Member
 
Registered: Feb 2002
Distribution: Debian / Debian-based
Posts: 58

Original Poster
Rep: Reputation: 15
Thanks jeremy.
 
Old 11-13-2012, 06:58 PM   #5
OsamaBinLogin
LQ Newbie
 
Registered: Sep 2004
Location: sili vali
Distribution: mostly Suse, try to use others too
Posts: 5

Rep: Reputation: 0
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
 
Old 11-14-2012, 08:11 AM   #6
linosaurusroot
Member
 
Registered: Oct 2012
Distribution: OpenSuSE,RHEL,Fedora,OpenBSD
Posts: 982
Blog Entries: 2

Rep: Reputation: 244Reputation: 244Reputation: 244
> 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.
 
Old 11-14-2012, 08:29 AM   #7
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,659
Blog Entries: 4

Rep: Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941
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.
 
Old 11-14-2012, 08:30 AM   #8
linosaurusroot
Member
 
Registered: Oct 2012
Distribution: OpenSuSE,RHEL,Fedora,OpenBSD
Posts: 982
Blog Entries: 2

Rep: Reputation: 244Reputation: 244Reputation: 244
Quote:
Originally Posted by sundialsvcs View Post
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
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Difference between Console, Shell, and Command Prompt Anupam Pathak Linux - Newbie 3 10-23-2005 04:40 AM
difference between shell scripting and c language gadekishore Linux - Software 5 10-17-2005 06:33 AM
Is there any difference between 2 shell scripts? tradewind Linux - Newbie 5 06-07-2004 07:52 PM
shell text fonts are larger than normal??? tsw Mandriva 8 05-12-2004 07:01 PM
difference of shell redragon7964 Linux - Newbie 2 04-06-2004 02:20 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 11:58 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration