Shell Processes   «Prev  Next»
Lesson 2 The login shell
Objective First Shell when you login into UNIX account.

First Shell when you login into UNIX account

The shell you run when you first log in to your UNIX account is typically defined in your /etc/passwd file. This file stores information about all user accounts on the system, including:
* Username
* Encrypted password
* User ID (UID)
* Group ID (GID)
* Full name (optional)
* Home directory
* Login shell
The login shell is specified in the last field of each user entry in the `/etc/passwd` file. This field typically points to the executable file for the default shell that the user will use upon login. Here are some common default shells you might encounter in UNIX systems:
  1. bash (Bourne Again SHell): The most widely used shell on modern UNIX systems, known for its flexibility and scripting capabilities.
  2. sh (Bourne Shell): The original Unix shell, still used in some environments for its simplicity and compatibility.
  3. csh (C Shell): Offers features similar to the C programming language, including syntax like command history and aliases.
  4. ksh (Korn Shell): A powerful shell with features borrowed from both bash and sh, popular for scripting tasks.
Finding Your Default Shell: There are a couple of ways to find out which shell is your default login shell:
  1. Check the /etc/passwd file (requires root privileges): You can use a command like `cat /etc/passwd` (cautiously, as it reveals encrypted passwords) to view the file contents. Look for your username entry and see what's listed in the last field. This will be the path to your default shell executable.
  2. Use the `SHELL` environment variable: This variable holds the path to your login shell. You can display its value using the command `echo $SHELL`.

Changing Your Default Shell: If you have permission (usually requires administrator privileges), you can change your default shell by modifying the `/etc/passwd` file. Edit the last field of your user entry to point to the desired shell executable. However, it's generally recommended to consult with your system administrator before making such changes.
Question: Which shell is run when you first login to your UNIX account?
When you first login to a shell account on a UNIX system, UNIX will start a shell for you and print a shell prompt on your screen. UNIX looks at the file /etc/passwd
[[The /etc/passwd file]]
to determine which shell you will use. This file is maintained by the system administrator for your system and contains login information for each user on the system. This information includes a user’s login name, home directory,login shell, and other information. Each line of the file shows information for a different login name on the system. The diagram below shows a sample line from this file.
Password File
sbarr59:abci+!.DSS243:209:1:/home/sbarr59:/bin/ksh

To change your default shell, ask your system administrator to change the /etc/passwd file.

You can use any Shell you want

No matter what your login shell, you can change to a new interactive shell at any time. You will learn more on this later in this module. You also may write shell scripts for any shell found on the machine regardless of the type of your login shell. Later in this module you will see how to indicate the shell for which a script was written.
  1. Interactive Shell: When a shell prints a prompt on your terminal screen and is waiting for you to enter commands, it is referred to as an interactive shell. The line where you type the commands is called the command line. When you run an interactive shell, it is functioning as a command line interface. Sometimes abbreviated CLI, this is a generic computer term referring to a program that presents you with a command line. The term command line interface is not restricted to shell programs.
  2. Non-interactive Shell: The shell may also be used as a programming language to string together a series of UNIX commands. This is a non-interactive use of the shell. Commands are typed into a file ahead of time and then run as a group. This course focuses on the non-interactive use of the shell.

Login Shell - Exercise

Click the exercise link below to practice looking up your own login shell in the /etc/passwd file.
login shell - Exercise
The next lesson is about shell processes.

SEMrush Software