⣿ ZOTHOS × 1NC0GN30 30 DAYS OF LINUX FUNDAMENTALS · TUI (./control-panel) + WEB GUI · 90 MISSIONS
← Back to 30-Day Curriculum

WEEK 2 · SYSTEM OPS · TUI: ./control-panel --day 8

Day 08: Bash Scripting: Variables, Conditionals & Functions

Write executable Bash scripts with variables, if/else branches, loops, and reusable functions.

XP 0
Streak 0
Command Mastery 0%
Study Music

YouTube Study Radio

Pick a track or paste any YouTube URL.

🍳 Breakfast (Syntax) Session

Type commands, build streaks, and then review the source guide.

Live Terminal Drill

Re-type the command exactly to clear each challenge.

target$ loading...

0 / 12 mastered

    Command Board

    Tap a command when you practiced it in your own terminal.

    Command Intel

    Meaning

    Command explanation will appear here.

    Sample Output

    Output preview will appear here.

    Useful Fun Fact

    Fun facts about the active command will appear here.

    Last Run Output

    Run a command to see result feedback.

    Knowledge Boost

    Faster learning with topic cues, mini-missions, and external docs.

    Key Topics

    ⚡ 60-Second Mental Model (Student Digest)IntroductionLessons1. Shell Scripting Basics

    Mini Missions

    • Mission 1: Run bash and explain the output in one sentence.
    • Mission 2: Run chmod +x and explain the output in one sentence.
    • Mission 3: Run echo and explain the output in one sentence.
    • Mission 4: Run mkdir -p /tmp/linux-dojo-day-08 && cd /tmp/linux-dojo-day-08 and explain the output in one sentence.

    📖 Digestible Study Guide & Visual Architecture

    Source: day-08-breakfast-guide.md · Synced with ./control-panel --day 8

    Day 08 · Breakfast — Bash Scripting Foundations: Variables, Conditionals & Functions



    ZothOS × 1nc0gn30 Linux Dojo · Phase: Week 2 (System Ops) · Session: Breakfast (Morning Foundation & Core Command Syntax)

    Core Commands: bash, chmod +x, echo, read, if/else, for


    ⚡ 60-Second Mental Model (Student Digest)



    ╔══════════════════════════════════════════════════════════════════════════════╗
    ║  ZOTHOS × 1NC0GN30 // PROCESS, KERNEL & NETWORK OPERATIONS PIPELINE          ║
    ╠══════════════════════════════════════════════════════════════════════════════╣
    ║                                                                              ║
    ║  ┌─────────────────┐    fork() / execve()    ┌────────────────────────────┐  ║
    ║  │  PID 1: systemd │ ──────────────────────► │  Active Daemons & Tasks    │  ║
    ║  └────────┬────────┘                         │  • nice / renice [-20..19] │  ║
    ║           │                                  │  • SIGTERM(15) / SIGKILL(9)│  ║
    ║           ▼                                  └─────────────┬──────────────┘  ║
    ║  ┌─────────────────┐    /proc & sysctl       ┌─────────────▼──────────────┐  ║
    ║  │ Kernel Modules  │ ◄─────────────────────► │ Network & Storage Stack    │  ║
    ║  │ lsmod / modprobe│                         │ ip route • ss • /etc/fstab │  ║
    ║  └─────────────────┘                         └────────────────────────────┘  ║
    ╚══════════════════════════════════════════════════════════════════════════════╝


    Learning PillarHow to Practice This Session
    1. Native TUI (./control-panel)Run ./control-panel from repo root → Select Week 2 → Day 08 → Breakfast to drill interactive C lessons & quizzes.
    2. Web Workstation (astro-ui)Open /day/8 → Select Breakfast tab → Type each target command in the live Mission Terminal to earn XP & streak mastery.
    3. Safe Local SandboxRun mkdir -p /tmp/linux-dojo-day-08 && cd /tmp/linux-dojo-day-08 to test every flag below without touching production files.




    Introduction



    Welcome to the study guide for Shell Scripting and Package Compilation! This guide covers key concepts and practices essential for mastering shell scripting and understanding package compilation.

    Lessons



    1. Shell Scripting Basics



    Description:

    Shell scripting automates tasks in Unix-based systems by writing a sequence of commands in a file. These scripts streamline workflows, manage system configurations, and perform repetitive tasks efficiently.

    Key Concepts:

  • Shebang (#!/bin/bash): Specifies the shell interpreter used to execute the script.

  • Common Use Cases: Backup scripts, batch processing, environment setup.


  • Example:

    #!/bin/bash
    echo "Hello, World!"

    Instructions:

    Save the script as hello.sh.
    Make it executable: chmod +x hello.sh.
    Run it: ./hello.sh.
    Additional Resources:

    The Linux Command Line by William Shotts

    GNU Bash Manual

    2. Package Compilation
    Description:

    Compiling software from source allows customization of installations, performance optimization, and patch application.

    Key Concepts:

    Steps: Download source code, extract it, configure build, compile, install binaries.
    Example Commands:

    Copy code
    wget http://example.com/package.tar.gz
    tar -xvf package.tar.gz
    ./configure
    make
    sudo make install

    Additional Resources:

    Linux From Scratch
    GNU Autotools Documentation

    3. Variables in Shell Scripts
    Description:

    Variables store data in scripts, making them dynamic and adaptable.

    Key Concepts:

    Creating Variables: Variables hold strings, numbers, or command output.
    Usage: $variable to access the variable's value.
    Example:

    Copy code
    my_variable="Hello, World!"
    echo $my_variable

    Additional Resources:

    Bash Scripting Tutorial

    4. Control Structures in Shell Scripts
    Description:

    Control structures like if-else and loops (for, while) automate decision-making and repetitive tasks.

    Key Concepts:

    if-else Statements: Conditional execution of commands.
    Loops: Iterate over data sets.
    Example:

    Copy code
    if [ $my_variable = "Hello, World!" ]; then
      echo "Match found!"
    else
      echo "No match."
    fi
    
    for i in 1 2 3; do
      echo $i
    done

    Additional Resources:

    Advanced Bash-Scripting Guide

    5. Functions in Shell Scripts
    Description:

    Functions organize reusable code, enhancing script readability and maintainability.

    Key Concepts:

    Defining Functions: Create blocks of reusable code.
    Syntax: [function_name]() { [commands]; }
    Example:

    Copy code
    my_function() {
      echo "Hello, World!"
    }
    my_function

    Additional Resources:

    Bash Reference Manual

    6. Package Configuration Options
    Description:

    ./configure scripts customize the build process by setting paths and enabling/disabling features.

    Key Concepts:

    --prefix Option: Sets the installation directory.
    Customizing Builds: Use various options to tailor the build.
    Example:

    Copy code
    ./configure --prefix=/usr/local
    ./configure --enable-debug

    Additional Resources:

    GNU Autoconf Documentation

    Questions

    1. What is the purpose of the #!/bin/bash line in a shell script?
    Answer:

    The shebang line specifies the shell interpreter as /bin/bash.

    2. What command is used to extract a tarball?
    Answer:

    The command to extract a tarball is tar -xvf.

    3. What is the purpose of the export command in shell scripting?
    Answer:

    The export command is used to make a variable available to subprocesses.

    4. How do you write an if-else statement in a shell script?
    Answer:

    The syntax is if condition; then action; else alternative; fi.

    5. What is the difference between ./configure and ./configure --prefix=/usr/local?
    Answer:

    The latter sets the installation prefix to /usr/local.

    6. How do you define a function in a shell script?
    Answer:

    A function is defined using the syntax my_function() { commands; }.

    This guide provides a comprehensive overview and resources to deepen your understanding of shell scripting and package compilation. Happy studying!