Based on the Linux Master 1 exam syllabusReport an error
exported: shell variables are not inherited by children, environment variables are inherited (but never flow back up to the parent).set (shell + environment + functions), env (environment only), and export (promotion) are an exam favorite./etc/profile → ~/.bash_profile; an interactive shell reads /etc/bashrc → ~/.bashrc. Use source to apply changes immediately.From the Thompson shell in 1971, to the Bourne shell (sh) in 1977, to Bash in 1989 — the shell is the program Linux users meet first and most often. For the Level 1 exam, the shell is treated not as a mere "command input box" but as an interpreter language and a user environment in one.
1. Print prompt → wait for user input
2. Read the input line (read)
3. Split into tokens + expand metacharacters/wildcards (parsing & expansion)
4. Perform variable substitution and command substitution
5. Decide whether it is a builtin or an external command
6. If external, search PATH for the executable
7. Create and run a child process via fork() → exec()
8. Wait for it to finish with wait() and collect the exit status
9. Print the prompt againShells are divided into "interactive shells" and "non-interactive shells". Typing directly in a terminal gives an interactive shell; running a script file gives a non-interactive one. They read different initialization files — that difference is the heart of today's last topic.
The exam asks about each shell's developer, family, and features. They split broadly into the Bourne shell family (sh → ksh → bash) and the C shell family (csh → tcsh).
| Shell | Name | Developer | Year | Family | Features |
|---|---|---|---|---|---|
sh | Bourne Shell | Stephen Bourne | 1977 | Bourne | The first standard shell, the baseline for scripts |
csh | C Shell | Bill Joy | 1978 | C | Borrowed C language syntax, introduced history and alias |
tcsh | TENEX C Shell | - | 1983 | C | Improved csh, command completion |
ksh | Korn Shell | David Korn | 1983 | Bourne | sh compatible + csh features merged, arithmetic capabilities |
bash | Bourne-Again Shell | Brian Fox | 1989 | Bourne | The GNU default shell, the Linux standard |
zsh | Z Shell | Paul Falstad | 1990 | Bourne | Powerful autocompletion and plugins, macOS default |
dash | Debian Almquist | - | 2002 | Bourne | Lightweight and fast POSIX sh, Debian's /bin/sh |
The name "Bourne-Again" in Bash is a pun on the Bourne shell being "born again". It also sounds just like the religious phrase "born-again", which shows the typical GNU wit.
/etc/shells file./etc/passwd.cat /etc/shells # list of installed shells
echo $SHELL # path of the current login shell
echo $0 # name of the currently running shell
grep "^$(whoami):" /etc/passwd # check the login shell of my account
chsh -s /bin/zsh # change the default login shell to zsh (change shell)⚠️ Trap:
$SHELLpoints to the "default shell assigned at login", not "the shell running right now". Even if you log in with bash and then runzshmanually,$SHELLstill shows/bin/bash. To see the shell that is actually running, useecho $0orps -p $$.
export, so it is inherited by child processes.# Declare a shell variable — valid only in the current shell
NAME="linux"
echo $NAME # linux
# Promote it to an environment variable — inherited by children
export NAME
# Or declare and export in one line
export PROJECT="cert"Seeing this difference for yourself is the key to understanding it.
# Try it yourself: shell variables are not inherited by children
LOCAL_VAR="only-here"
export GLOBAL_VAR="passed-down"
bash # enter a child shell
echo "$LOCAL_VAR" # (blank line) — not inherited
echo "$GLOBAL_VAR" # passed-down — inherited
exit # return to the parent shellVariable inheritance flows in one direction only, parent → child. Changing an environment variable in a child shell never affects the parent shell, because the child starts with a "copy" of the parent's environment. That is why a variable changed with export inside a script does not remain in the parent shell that called the script.
These three commands are often confused, so you need to tell them apart precisely.
| Command | What it shows | Purpose |
|---|---|---|
set | Shell variables + environment variables + functions, everything | Print all variables of the current shell |
env | Environment variables only | Print environment variables, run a command in a temporary environment |
export | Only exported variables (environment variables) (export -p) | Promote a shell variable to an environment variable |
unset | - | Delete a variable or function |
set | head # all variables (shell+environment+functions) — the longest output
env # environment variables only
export -p # list of exported variables
unset NAME # delete a variable
declare -p NAME # check a variable's attributes and value (bash builtin)env is used not only for printing but also to run a command with a temporarily modified environment.
# Temporarily set LANG to C and run date (the current shell environment is unchanged)
env LANG=C date
# Clear all environment variables and run in a clean environment
env -i bashBesides printing variables, set is also used to turn shell options on and off. set -x traces the commands being executed (debugging), set -e stops immediately on an error, and set -u raises an error when an undefined variable is used. The set -euo pipefail at the top of a script is exactly this combination of options, an idiom for safe scripts.
| Variable | Meaning |
|---|---|
PATH | List of directories to search for command executables (separated by :) |
HOME | The user's home directory |
PWD | The current working directory |
SHELL | Path of the default login shell |
USER / LOGNAME | Login user name |
LANG | Language and locale settings |
PS1 | The default prompt string |
TERM | Terminal type |
HISTSIZE | Number of history entries kept in memory |
MAIL | Path of the mailbox |
echo $PATH
# /usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin
# Add a directory to PATH (putting it first makes it searched first)
export PATH=/opt/myapp/bin:$PATH⚠️ Trap: When setting
PATH, do not overwrite the existing value. Writingexport PATH=/opt/binleaves you unable to find even basic commands likelsandcat. You must include the existing $PATH, as inexport PATH=/opt/bin:$PATH. Also, PATH is searched from the front, so if the same command name exists in several places, the one in the directory that appears first is executed.
Which configuration files bash reads at startup depends on (1) whether it is a login shell and (2) whether it is interactive. This is within the Level 1 exam scope.
/etc/profile, /etc/profile.d/*.sh, /etc/bashrc (or /etc/bash.bashrc) — apply to all users. Only the administrator (root) can modify them.~/.bash_profile, ~/.bash_login, ~/.profile, ~/.bashrc, ~/.bash_logout — located in each user's home directory.A login shell (console login, SSH connection, etc.) reads files in the following order.
1. /etc/profile (global — all users)
└─ /etc/profile.d/*.sh (collection of global settings)
2. In the user's home, run only "the first one found" of:
~/.bash_profile → ~/.bash_login → ~/.profile
3. At logout: ~/.bash_logout~/.bash_profile so that it explicitly loads ~/.bashrc.# Typical contents of ~/.bash_profile
if [ -f ~/.bashrc ]; then
. ~/.bashrc # load .bashrc ( . is short for source)
fiAn interactive shell that does not go through login, such as opening a new tab in a terminal emulator, reads only the following.
1. /etc/bashrc (or /etc/bash.bashrc, global)
2. ~/.bashrc (user)To sum up — .bash_profile is read once at login, and .bashrc is read every time a new shell is launched. So the convention is to put "settings needed in every shell every time", like aliases and functions, in .bashrc, and "settings that are set once at login and inherited by children", like environment variables, in .bash_profile.
| File | Scope | When it runs |
|---|---|---|
/etc/profile | Global | When a login shell starts (all users) |
/etc/bashrc | Global | When an interactive shell starts (all users) |
~/.bash_profile | Personal | When a login shell starts |
~/.bashrc | Personal | When an interactive shell starts |
~/.bash_logout | Personal | At logout |
~/.profile | Personal | Fallback when .bash_profile is absent (sh compatible) |
~/.profile is not bash-specific; it is a Bourne-shell-compatible file. Debian/Ubuntu traditionally ship ~/.profile instead of ~/.bash_profile. Since bash looks for .bash_profile first, then .bash_login, and then .profile, on Ubuntu .profile effectively serves as the login script.
To apply a modified configuration file immediately without logging out and back in, use source or . (dot).
source ~/.bashrc # re-read the contents of .bashrc into the current shell
. ~/.bashrc # exactly the same as above ( . is the short form of source)You must not run it like bash ~/.bashrc. That launches a new child shell, applies the settings only inside it, and then ends, so nothing changes in the current shell. You must use source (or .) to read the file inside the current shell process for the change to persist. This is the concept directly tied to shell variable inheritance (parent↔child).
The source command first appeared in the C shell, while the Bourne family did the same job with just . (dot). bash supports both notations. If the exam asks "Which command does the same job as . file?", the answer is source.
Tomorrow we build on this foundation and cover redirection and pipes.
/etc/profile and ~/.bash_profile.export that is inherited by child processes. It never travels back up to the parent, though.export : The command that promotes a shell variable to an environment variable.set vs env : set shows shell variables, environment variables, and functions all together, while env shows only environment variables.~/.bash_profile vs ~/.bashrc : The former is read once at login, the latter every time a new shell is launched.source (.) : A command that reads a file inside the current shell to apply settings immediately. The result differs from bash file.Click a choice to reveal the answer and explanation.
Question 1
Which of the following shell family classifications is incorrectly matched?
Question 2
Which command correctly turns the shell variable VAR into an environment variable so that it is inherited by child processes?
Question 3
Which global configuration file does a login shell read first?
Question 4
Which command prints only the environment variables set in the current shell?
Question 5
What is the correct way to apply a modified .bashrc to the current shell immediately, without logging out?
Question 6
Which of the following statements about the PATH environment variable is incorrect?
Question 7
Which user configuration file does a non-login interactive shell (opening a new tab in a terminal) read?