1. What is a Shell Script?

A shell script is simply a text file containing a list of Linux commands.

Instead of typing commands one by one, we write them into a file and run everything at once.

Key Features:

  • ๐Ÿ“„ Usually ends with .sh
  • ๐Ÿค– Executed by a shell like Bash
  • โšก Used for Automation (backups, installs, monitoring)

2. Understanding the Structure

Every script starts with a special line called the Shebang.

#!/bin/bash echo "Hello Workshop"

Breakdown:

3. Making it Executable

By default, Linux prevents files from running as programs for security.

You MUST give Execute Permission before running a script.

chmod +x script.sh

chmod = Change Mode
+x = Add Execute permission

4. Step-by-Step Activity

Step 1: Create the File

Open your terminal editor:

nano script.sh

Step 2: Add Content

Type this inside the editor:

#!/bin/bash echo "Hello Workshop"

Save & Exit: Press CTRL+O (Enter) then CTRL+X.

Step 3: Make Executable

chmod +x script.sh

Step 4: Run It

Use ./ to run from current directory:

./script.sh

Output:

Hello Workshop

5. Real-World Power

Scripts can combine multiple commands to give you instant system reports.

#!/bin/bash echo "User: $USER" date uptime

This single script prints who you are, the current time, and how long the computer has been on.

๐Ÿงช Student Tasks

Task 1: Personal Greeting

Modify script.sh to print:

#!/bin/bash echo "Welcome to Linux Workshop" echo "Today we learn Shell Scripting"

Task 2: System Info Script

1. Create info.sh
2. Add the following code:

#!/bin/bash echo "Current User:" whoami echo "Current Directory:" pwd echo "Current Date:" date

3. Remember to chmod +x info.sh before running!