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.
Breakdown:
#!/bin/bashโ Tells Linux to use the Bash interpreter.echo "..."โ Prints text to the terminal screen.
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 = Change Mode+x = Add Execute permission
4. Step-by-Step Activity
Step 1: Create the File
Open your terminal editor:
Step 2: Add Content
Type this inside the editor:
Save & Exit: Press CTRL+O (Enter) then CTRL+X.
Step 3: Make Executable
Step 4: Run It
Use ./ to run from current directory:
Output:
5. Real-World Power
Scripts can combine multiple commands to give you instant system reports.
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:
Task 2: System Info Script
1. Create info.sh
2. Add the following code:
3. Remember to chmod +x info.sh before running!