Based on the Linux Master 2 exam syllabusReport an error
bash. It is short for Bourne Again SHell.echo $SHELL; the list of available shells is in /etc/shells; and the command to change it is chsh./etc/passwd.When you type ls -l /etc and press Enter, the following happens inside the shell, in order.
1. Read Receives the line you typed
2. Split Splits on whitespace into command (ls), option (-l), and argument (/etc)
3. Expand Replaces $variables, wildcards (*), and aliases with real values
4. Look up Checks whether it is a builtin; if not, searches PATH for an executable
5. Execute Creates a child process and runs that program
6. Wait Receives the exit status when it finishes and shows the prompt againls *.txt it is the shell, not ls, that replaces * with file names. ls just receives the list of file names that has already been expanded.| Category | What it is | Examples | How to check |
|---|---|---|---|
| Builtin command | A command that is built into the shell itself. It does not create a new process | cd, echo, export, alias, history, exit | type cd |
| External command | A command that exists as a separate executable file on disk | ls, cp, cat, vi | which cat |
type cd
# cd is a shell builtin
type cat
# cat is /usr/bin/cat
type ls
# ls is aliased to `ls --color=auto'There is a reason
cdis a builtin. Changing directories changes the shell's own current location, so a child process cannot do it on the shell's behalf. Even if the child moves, the parent shell stays where it was.
Thompson shell (1971)
│
┌─────────────────┴─────────────────┐
│ │
Bourne shell (sh, 1977) C shell (csh, 1978)
Stephen Bourne Bill Joy
│ │
┌────┴────┬──────────┐ │
│ │ │ │
ksh bash dash tcsh
(Korn) (GNU, 1989) (improved)
│ │
└────► zsh (absorbs features of ksh, bash, tcsh)| Shell | Meaning of the name | Creator | Family | Features |
|---|---|---|---|---|
| sh | Bourne shell | Stephen Bourne | Bourne | The first standard shell. Few features, but available everywhere |
| csh | C shell | Bill Joy | C | Syntax similar to the C language. Introduced history and aliases |
| tcsh | TENEX C shell | — | C | Improved csh. Command completion |
| ksh | Korn shell | David Korn | Bourne | sh-compatible plus csh features combined |
| bash | Bourne Again shell | Brian Fox | Bourne | The default Linux shell. A GNU project |
| zsh | Z shell | Paul Falstad | Bourne | Powerful autocompletion. The default shell on macOS |
| dash | Debian Almquist shell | — | Bourne | Light and fast. Used only for scripts |
Expect a question that tests the families. Only
cshandtcshare C family; all the others are Bourne family. It helps to remember that only the two with a "c" in their name are grouped separately.
The history of shells is easy to memorize if you read it as "who added the convenience features that earlier shells lacked." The order of appearance is sh (1977) → csh (1978) → ksh (1983) → bash (1989) → zsh (1990).
| Feature | sh | csh | tcsh | ksh | bash |
|---|---|---|---|---|---|
| History (command history) | ✕ | ○ | ○ | ○ | ○ |
| Alias | ✕ | ○ | ○ | ○ | ○ |
Job control (fg, bg) | ✕ | ○ | ○ | ○ | ○ |
| Command-line editing | ✕ | ✕ | ○ | ○ | ○ |
| Compatible with sh scripts | — | ✕ | ✕ | ○ | ○ |
$, the C family uses %, and in either one root gets #.ls -l /bin/sh
# lrwxrwxrwx. 1 root root 4 ... /bin/sh -> bash ← Red Hat family
# lrwxrwxrwx 1 root root 4 ... /bin/sh -> dash ← Debian/UbuntuModern Linux has no real Bourne shell.
/bin/shis a symbolic link to another shell. The Red Hat family points it at bash, and the Debian family points it at the lightweight dash. That is why dash is listed as "scripts only" in the table.
The Level 2 exam asks directly who created each shell.
| Shell | Creator |
|---|---|
| sh | Stephen Bourne |
| csh | Bill Joy |
| ksh | David Korn |
| bash | Brian Fox |
echo $SHELL # /bin/bash ← login shell
echo $0 # -bash ← the shell currently running
cat /etc/shells # list of shells available on this system
which bash # /usr/bin/bash| Method | What it tells you |
|---|---|
echo $SHELL | The login shell (the shell set as the default) |
echo $0 | The shell currently running |
/etc/shells | The file listing available shells |
7th field of /etc/passwd | That user's login shell |
$SHELLand$0can differ. If you logged in with bash but then ranzshinside it,$SHELLis still/bin/bashwhile$0becomeszsh.
cat /etc/shells
# /bin/sh
# /bin/bash
# /usr/bin/sh
# /usr/bin/bash
# /bin/tcsh
# /bin/zsh
grep "^user:" /etc/passwd
# user:x:1000:1000:Test User:/home/user:/bin/bash
ps -p $$
# PID TTY TIME CMD
# 2314 pts/0 00:00:00 bash/etc/shells lists shells as absolute paths, one per line. The list varies depending on which shells are installed.$$ is the PID of the current shell. That makes ps -p $$ the most reliable way to check "which shell is running right now."echo $0 starts with a hyphen, like -bash, it marks a login shell. A shell launched again from inside it shows up as bash without the hyphen.$SHELL is just a variable filled in at login from the /etc/passwd value. It does not change on its own when you run another shell.chsh -s /bin/zsh # set my login shell to zsh
chsh -s /bin/zsh alice # set alice's login shell (root privileges)
chsh -l # list available shellschsh (change shell) edits the last field of /etc/passwd. It takes effect from the next login./etc/shells./sbin/nologin or /bin/false as the shell. This keeps the account but blocks logins. user:x:1000:1000:Test User:/home/user:/bin/bash
└─┬─┘
└── 7th field = login shell| Method | Who can use it | Notes |
|---|---|---|
chsh -s shell [user] | The user (own shell), root (anyone's) | Regular users must confirm their password |
usermod -s shell user | root | The -s option of the command that edits account attributes |
Edit /etc/passwd directly | root | Edit the 7th field. One typo can lock out logins |
chsh -s /bin/zsh
# Changing shell for user.
# Password:
# Shell changed.
echo $SHELL
# /bin/bash ← still unchanged. You must log in again for it to change
grep "^user:" /etc/passwd
# user:x:1000:1000:Test User:/home/user:/bin/zshchsh does not touch the running shell; it only edits the value to be used at the next login.zsh. When you exit, you return to the original shell and /etc/passwd is unchanged.chsh -l is supported on the Red Hat family. The Debian family's chsh does not have this option, so use cat /etc/shells instead.useradd -s /bin/zsh alice.| Shell | When someone tries to connect |
|---|---|
/sbin/nologin | Shows the message "This account is currently not available." and disconnects |
/bin/false | Disconnects immediately without saying anything |
grep nologin /etc/passwd | head -3
# bin:x:1:1:bin:/bin:/sbin/nologin
# daemon:x:2:2:daemon:/sbin:/sbin/nologin
# apache:x:48:48:Apache:/usr/share/httpd:/sbin/nologinuserdel). The account and file ownership stay as they are, and only the login is blocked./usr/sbin/nologin.| Category | When | Configuration files read |
|---|---|---|
| Login shell | At login, su - | /etc/profile, ~/.bash_profile |
| Non-login shell | When opening a new terminal window | ~/.bashrc |
su and su - shows up here too. Adding the hyphen starts a login shell.Tomorrow we cover the values the shell remembers: shell variables and environment variables.
/etc/passwd./etc/shells : A file containing the list of paths of shells that can be used on the system.chsh : The command that changes the login shell. It takes effect from the next login./sbin/nologin : A shell assigned to block logins. The account exists but cannot be connected to.Click a choice to reveal the answer and explanation.
Question 1
Which of the following is the default shell on Linux and is short for Bourne Again SHell?
Question 2
Which of the following shells belongs to the C shell family?
Question 3
Who developed the Korn shell?
Question 4
Which of the following files contains the list of shells that can be used on the system?
Question 5
Which of the following commands changes a user's login shell?