41

UNIX: The Complete Reference, Second Edition by Kenneth H. Rosen et al.

You can start another shell after you log in by using the name of the shell as a command; for example, to start the Korn shell, you could type ksh at the command prompt. This type of shell is not a login shell, and you do not have to log in again to use it, but it is still an interactive shell, meaning that you interact with the shell by typing in commands (as opposed to using the shell to run a script, as discussed in Chapter 20). The instances of the shell that run in a terminal window when you are using a graphical interface are also interactive non-login shells. When you start a non-login shell, it does not read your .profile, .bash_profile, or .login file (or your .logout file), but it will still read the second shell configuration file (such as .bashrc). This means that you can test changes to your .bashrc by starting another instance of the shell, but if you are testing changes to your .profile or .login, you must log out and then back in to see the results.

I was going through above lines and I don't understand what it means by interactive shell. Is it true that .profile is not read if I am using terminal?

Moreover, what does it mean when you say that bourne is not is an interactive shell while bash/csh is an interactive shell?

Jeff Schaller
  • 67,283
  • 35
  • 116
  • 255
munish
  • 7,987

1 Answers1

49

An interactive shell is simply any shell process that you use to type commands, and get back output from those commands. That is, a shell with which you interact.

So, your login shell is interactive, as are any other shells you start manually, as described in the excerpt you quoted in your question. By contrast, when you run a shell script, a non-interactive shell is started that runs the commands in the script, and then exits when the script finishes.

The Bourne shell can be used as an interactive shell, just like bash or tcsh. In fact, many systems, such as FreeBSD, use sh as the default user shell. Modern shells like bash, zsh, tcsh, etc have many features that Bourne shell doesn't have, that make them more comfortable and convenient for interactive use (command history, completion, etc).

Interactive non-login shells (that is, shells you start manually from another shell or by opening a terminal window) don't read your .login or .profile files. These are only read and executed by login shells (shells started by the login system process, or by your X display manager), so the commands and settings they contain are only applied once, at the beginning of your login session. So, when you start a terminal, the shell that it spawns for you does not read your login files (.login for c-style shells, .profile for bourne style shells), but it does read the .cshrc, .bashrc etc files.

D_Bye
  • 13,977
  • 3
  • 44
  • 31
  • 1
    It is possible to run a shell as a non-interactive login shell. – jw013 Jul 18 '12 at 15:01
  • True, but potentially confusing! – D_Bye Jul 18 '12 at 15:04
  • ksh is also a modern shell :-) See http://www2.research.att.com/sw/download/ and use the menu on the left-hand margin to navigate to AST->ksh->overview. A new release comes out several times a year from David Korn and Glen Fowler. Good luck to all. – shellter Jul 19 '12 at 04:24
  • 1
    @shellter - yes, indeed. But it's not one I've ever used, and I had to stop enumerating shells somewhere! ;-) – D_Bye Jul 19 '12 at 10:40
  • 1
    You've said The Bourne shell can be used as an interactive shell, just like bash or tcsh. Isn't Bourne shell the same as bash? – Mr.Web Sep 03 '18 at 17:56
  • @Mr.Web - bash is a more recent shell that is designed to be sh-compatible, but it has many features unknown in sh. In reality, on many systems, the shell that purports to be sh these days is likely actually to be ash, dash or some other more recent shell in the Bourne family. FreeBSD, for example, uses ash as its sh implementation. – D_Bye Sep 03 '18 at 23:29
  • 2
    @D_Bye ok so Bourne shell is not necessarily "Bourne again shell" (bash) but a whole family – Mr.Web Sep 04 '18 at 06:53