Fundamentals 25 min read

13 Essential Shell Questions Every Linux Beginner Should Know

This article compiles thirteen fundamental Linux shell questions covering the origin of the term "shell", the relationship between PS1 and carriage return, echo command usage, differences between single and double quotes, variable assignment, export behavior, and practical quoting techniques, providing clear explanations and examples for each.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
13 Essential Shell Questions Every Linux Beginner Should Know

Question 1: Why is it called a shell?

Question 2: How does the shell prompt (PS1) relate to Carriage Return (CR)?

Question 3: How much do you know about the echo command?

Question 4: What is the difference between double quotes (") and single quotes (')?

Question 5: What is the difference before and after using export with var=value?

This article is整理并转自CU上的帖子 [学习共享] shell 十三問?, originally posted in 2003, now simplified for a Chinese‑English audience.

Question 1: Why is it called a shell?

Before defining shell, consider the relationship between the user and the computer. The hardware runs the kernel, but users cannot interact with the kernel directly; they use an "outer shell" program – the shell – to communicate with the kernel. Thus the shell is a user‑system interface, essentially a command interpreter that translates user commands to the kernel and returns results.

When you log in, you obtain a login (primary) shell. Commands you type create child processes (fork). Scripts run in a non‑interactive subshell. Different kernels can be paired with different shells; Linux typically provides several shells listed in /etc/shells. The two main families are:

sh:
sh
bash
csh:
csh
tcsh
ksh

Most Linux distributions default to bash because it is free software and powerful.

Question 2: How does the shell prompt (PS1) relate to Carriage Return (CR)?

After logging in, the cursor (a blinking block or underline) indicates where the next typed character will appear. The prompt (PS1) is the visible symbol left of the cursor, typically $ for normal users and # for root. The prompt tells the user that the shell is ready for input. When the user presses Enter, a Carriage Return (CR) character is sent, signalling the shell to execute the entered command line.

A command line consists of command-name options argument. The shell splits the line into fields using the Internal Field Separator (IFS), which defaults to space, tab, and newline.

The shell can obtain command names from explicit paths, aliases, functions, built‑ins, or any executable found in $PATH.

Question 3: How much do you know about the echo command?

The echo command prints its arguments to standard output (STDOUT). By default it appends a newline; the -n option suppresses this newline.

$ echo

$ echo -n

Common options: -e: enable backslash‑escaped characters -E: disable backslash escapes (default) -n: omit the trailing newline

Supported escape sequences include \a (bell), \b (backspace), \c (suppress newline), \E (escape), \f (form feed), \n (newline), \r (carriage return), \t (tab), \v (vertical tab), octal \nnn, and literal backslash \\.

Examples:

$ echo -e "a\tb\tc
d\te\tf"
a b c
d e f
$ echo -e "\141\011\142\011\143\012\144\011\145\011\146"
a b c
d e f
$ echo -e "\x61\x09\x62\x09\x63\x0a\x64\x09\x65\x09\x66"
a b c
d e f

Echo is also useful for checking variable values:

$ A=B
$ echo $A
B
$ echo $?
0

Question 4: What is the difference between double quotes (") and single quotes (')?

Characters in a command line are either literal (plain text) or meta (special meaning). Single quotes (hard quoting) disable all meta characters inside them. Double quotes (soft quoting) disable most meta characters but still allow variable expansion ( $) and command substitution.

Examples:

$ A=B C   # space is not quoted → interpreted as two commands (A=B and C)
$ A="B C" # space inside double quotes → treated as a single argument
$ echo "$A"
B C
$ echo '$A'
$A

Quoting also affects how the shell treats IFS, CR, and other meta characters. Hard quoting can be used to pass characters like { and } to tools such as awk without the shell interpreting them:

$ awk '{print $0}' 1.txt

Question 5: What is the difference before and after using export with var=value?

Variables defined in the current shell are local. Using export turns them into environment variables visible to child processes.

$ A=B
$ export A   # now A is an environment variable

Export can be combined with variable substitution:

$ A=B
$ B=C
$ export $A   # $A expands to B, so B becomes exported, not A

To remove a variable, use unset, which also performs substitution:

$ A=B
$ B=C
$ unset $A   # expands to unset B, removing B

Setting a variable with name=value follows strict rules: no IFS around =, name cannot start with a digit or contain $, and names are case‑sensitive. Variable substitution uses $name and can be combined with braces for clarity, e.g., ${A}E to append E to A without ambiguity.

Understanding the distinction between a null value ( var=) and an unset variable ( unset var) is crucial for advanced scripting, as they behave differently in parameter expansions such as ${var=default}.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

VariablesEnvironment Variablesquoting
MaGe Linux Operations
Written by

MaGe Linux Operations

Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.