LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices

Reply
 
Search this Thread
Old 04-22-2010, 06:57 PM   #1
Josh000
Member
 
Registered: Aug 2009
Distribution: Slackware 13 64bit
Posts: 534

Rep: Reputation: 35
Login and Interactive shells


I am having trouble distinguishing between login and interactive shells as they relate to terminals.

I understand that a login shell is what is started when you login, and an interactive shell is used by scripts and such.

I also get that terminals will use an interactive shell by default.

What I don't understand is why interactive shells have no prompt by default. Is their a way to get an interactive shell to inherit the normal PS1 prompt?

Is it considered bad to do this? Would it be better to have terminals start login shells, and if so why or why not?
 
Old 04-22-2010, 07:29 PM   #2
Richard Cranium
Senior Member
 
Registered: Apr 2009
Location: Carrollton, Texas
Distribution: Slackware64 14.1
Posts: 1,494

Rep: Reputation: 437Reputation: 437Reputation: 437Reputation: 437Reputation: 437
xterm -ls
 
Old 04-22-2010, 07:49 PM   #3
Josh000
Member
 
Registered: Aug 2009
Distribution: Slackware 13 64bit
Posts: 534

Original Poster
Rep: Reputation: 35
Quote:
Originally Posted by Richard Cranium View Post
xterm -ls
I didn't ask how to start a login shell
 
Old 04-22-2010, 07:59 PM   #4
Richard Cranium
Senior Member
 
Registered: Apr 2009
Location: Carrollton, Texas
Distribution: Slackware64 14.1
Posts: 1,494

Rep: Reputation: 437Reputation: 437Reputation: 437Reputation: 437Reputation: 437
The trite answer would be that not having a spiffy prompt on the interactive shell allows you to tell the two environments apart. In addition, why would a script need a spiffy prompt? Note that you can go crazy creating the prompt string for your login shells by embedding `run-some-command-for-the-output` backtic commands in there.

Even so, launching an xterm from an xterm with a login shell should inherit the original environment, giving you the prompt that you seek.

FWIW, gnome-terminal has an option that allows you to launch them with a login shell. It's normally trivial to modify your window manager to allow you to launch an xterm with a login shell.
 
Old 04-22-2010, 09:02 PM   #5
Josh000
Member
 
Registered: Aug 2009
Distribution: Slackware 13 64bit
Posts: 534

Original Poster
Rep: Reputation: 35
Quote:
Originally Posted by Richard Cranium View Post
The trite answer would be that not having a spiffy prompt on the interactive shell allows you to tell the two environments apart. In addition, why would a script need a spiffy prompt? Note that you can go crazy creating the prompt string for your login shells by embedding `run-some-command-for-the-output` backtic commands in there.

Even so, launching an xterm from an xterm with a login shell should inherit the original environment, giving you the prompt that you seek.

FWIW, gnome-terminal has an option that allows you to launch them with a login shell. It's normally trivial to modify your window manager to allow you to launch an xterm with a login shell.
PS1 is exported in /etc/profile. Other variables such as PATH are correctly set, so why isn't PS1 set as well?

Is there a way to set PS1 for interactive shells?

Why do terminals start interactive shells rather than login shells?
 
Old 04-22-2010, 09:04 PM   #6
dugan
Senior Member
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 4,664

Rep: Reputation: 1440Reputation: 1440Reputation: 1440Reputation: 1440Reputation: 1440Reputation: 1440Reputation: 1440Reputation: 1440Reputation: 1440Reputation: 1440
Quote:
Originally Posted by Josh000 View Post
What I don't understand is why interactive shells have no prompt by default.
Because you don't have a .bashrc file by default.

Quote:
Is their a way to get an interactive shell to inherit the normal PS1 prompt?
Of course.

This is related:
http://www.linuxquestions.org/questi...prompt-798622/

Basically, create two files:

~/.bash_profile:
Code:
if [ -f ~/.bashrc ]; then
    . ~/.bashrc
fi
~/.bashrc:
Code:
. /etc/profile

Last edited by dugan; 04-22-2010 at 09:13 PM.
 
Old 04-22-2010, 10:41 PM   #7
Josh000
Member
 
Registered: Aug 2009
Distribution: Slackware 13 64bit
Posts: 534

Original Poster
Rep: Reputation: 35
Awesome, thanks.

I seem to hae picked up that is is better to have many interactive shells than many login shells. Is there any truth to this?
 
Old 04-23-2010, 09:02 AM   #8
rworkman
Slackware Contributor
 
Registered: Oct 2004
Location: Tuscaloosa, Alabama (USA)
Distribution: Slackware
Posts: 1,913

Rep: Reputation: Disabled
It depends on what you do in your $HOME/.bash_profile or $HOME/.profile (both of these are sourced when starting a login shell) and in the system-wide profile scripts. If, for example, you start something in $HOME/.profile that is a "long-running" process (e.g. gpg-agent, sets up environment variables for the entire login session and will be inherited by other processes that are started later), then you don't want it to be started multiple times.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Interactive and non-interactive shells? Tim356 Linux - Newbie 7 11-05-2008 10:32 PM
Login shells / Non-login shells tofee Linux - Newbie 1 03-24-2006 11:03 PM
Chainging the PATH on login shells cliff76 Debian 5 06-16-2005 03:52 PM
Bash and login shells Adrohak Linux - Software 3 11-18-2004 10:21 AM
Login shells vs non-login shells lsmith Linux - General 2 03-31-2004 07:29 PM


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

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration