Bird
Raised Fist0
Linux CLIscripting~5 mins

Shell concept (Bash, Zsh) in Linux CLI - Commands & Configuration

Choose your learning style10 modes available
Introduction
A shell is a program that lets you talk to your computer by typing commands. Bash and Zsh are popular shells that help you run commands, manage files, and automate tasks easily.
When you want to run commands to manage files or programs on your computer.
When you need to automate repetitive tasks like backups or file renaming.
When you want to customize your command prompt or environment for easier use.
When you want to write scripts to perform multiple commands automatically.
When you want to explore and learn how your operating system works through commands.
Commands
This command shows which shell you are currently using by printing the shell's path.
Terminal
echo $SHELL
Expected OutputExpected
/bin/bash
This command shows the version of Bash installed on your system to confirm it is available.
Terminal
bash --version
Expected OutputExpected
GNU bash, version 5.1.16(1)-release (x86_64-pc-linux-gnu) Copyright (C) 2020 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software; you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law.
This command shows the version of Zsh installed on your system to check if Zsh is available.
Terminal
zsh --version
Expected OutputExpected
zsh 5.8 (x86_64-ubuntu-linux-gnu)
This command changes your default shell to Zsh so that every new terminal session uses Zsh.
Terminal
chsh -s /bin/zsh
Expected OutputExpected
Password:
→
-s - Specifies the new shell to set as default
This command prints the name of the current shell session to confirm which shell you are using now.
Terminal
echo $0
Expected OutputExpected
zsh
Key Concept

If you remember nothing else, remember: a shell is your command-line helper that runs your commands and scripts.

Common Mistakes
Trying to run shell commands without knowing which shell is active.
Different shells can behave differently, so commands might not work as expected.
Always check your current shell with 'echo $SHELL' before running commands.
Changing the default shell without installing it first.
If the shell is not installed, the change will fail or cause login issues.
Verify the shell is installed using '--version' before changing it.
Not restarting the terminal after changing the default shell.
The shell change only applies to new sessions, so the current terminal still uses the old shell.
Close and reopen the terminal or log out and back in to start using the new shell.
Summary
Use 'echo $SHELL' to find out which shell you are using.
Check shell versions with 'bash --version' or 'zsh --version' to confirm availability.
Change your default shell with 'chsh -s /bin/zsh' and restart your terminal to apply.

Practice

(1/5)
1. What is a shell in Linux or macOS?
easy
A. A programming language for creating websites
B. A program that lets you type commands to control your computer
C. A graphical interface for editing photos
D. A type of hardware component inside the computer

Solution

  1. Step 1: Understand the role of a shell

    A shell is a program that takes your typed commands and runs them on the computer.
  2. Step 2: Compare options

    Options A, B, and C describe web programming, hardware, and graphics, which are not shells.
  3. Final Answer:

    A program that lets you type commands to control your computer -> Option B
  4. Quick Check:

    Shell = command program [OK]
Hint: Shell = command line program to control computer [OK]
Common Mistakes:
  • Thinking shell is hardware
  • Confusing shell with graphical apps
  • Mixing shell with programming languages
2. Which of these is the correct way to run a command with an option in Bash?
easy
A. ls -ll
B. ls -l -
C. ls l-
D. ls -l

Solution

  1. Step 1: Identify correct option syntax

    Options start with a dash (-) followed by letters, so '-l' is correct.
  2. Step 2: Check each option

    A: 'ls -l' is correct. B has extra dash, C has wrong order, D uses '-ll' which repeats the option unnecessarily.
  3. Final Answer:

    ls -l -> Option D
  4. Quick Check:

    Options start with dash and letter [OK]
Hint: Options start with dash (-) followed by letters [OK]
Common Mistakes:
  • Adding extra dash after options
  • Writing options without dash
  • Combining options incorrectly
3. What will the following Bash command output?
echo "Hello"; echo "World"
medium
A. Hello World (two lines)
B. Hello\nWorld
C. Hello World
D. Hello World

Solution

  1. Step 1: Understand the echo command

    Each echo prints its argument followed by a new line by default.
  2. Step 2: Analyze the command sequence

    First echo prints 'Hello' then newline, second echo prints 'World' then newline, so output is two lines.
  3. Final Answer:

    Hello World (two lines) -> Option A
  4. Quick Check:

    echo prints with newline [OK]
Hint: echo prints text then newline by default [OK]
Common Mistakes:
  • Thinking echo joins output on one line
  • Confusing literal \n with newline
  • Ignoring semicolon separates commands
4. What is wrong with this Bash script snippet?
for i in 1 2 3
do
echo $i
done
medium
A. Missing semicolon after '3'
B. Incorrect loop syntax, should use parentheses
C. No error, script runs fine
D. Missing 'do' keyword

Solution

  1. Step 1: Check for loop syntax

    The for loop syntax 'for i in 1 2 3; do ... done' is correct. The semicolon after '3' is optional if 'do' is on next line.
  2. Step 2: Verify keywords and structure

    'do' is present, parentheses are not needed in Bash for this loop, so no syntax error.
  3. Final Answer:

    No error, script runs fine -> Option C
  4. Quick Check:

    Bash for loop syntax correct without semicolon if newline before do [OK]
Hint: Newline before 'do' replaces semicolon in for loops [OK]
Common Mistakes:
  • Thinking semicolon is always required
  • Confusing Bash syntax with other languages
  • Missing 'do' keyword
5. You want to list all files in a directory including hidden ones, sorted by modification time. Which command should you use?
hard
A. ls -a -t
B. ls -l -h
C. ls -r -S
D. ls -d .*

Solution

  1. Step 1: Understand options needed

    '-a' shows all files including hidden, '-t' sorts by modification time.
  2. Step 2: Evaluate each option

    A: 'ls -r -S' reverses and sorts by size (no hidden). B: 'ls -l -h' long format with human sizes (no hidden, no time sort). C: 'ls -a -t' shows all including hidden, sorted by mod time. D: 'ls -d .*' shows only dot entries.
  3. Final Answer:

    ls -a -t -> Option A
  4. Quick Check:

    Show hidden + sort by time = ls -a -t [OK]
Hint: Use -a for hidden, -t for time sort [OK]
Common Mistakes:
  • Using -l instead of -a to show hidden
  • Confusing -S (size) with -t (time)
  • Using -d .* lists only hidden files
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard