SHELL SCRIPTING
π§ SHELL SCRIPTING REVIEWER
(Based on your handout )
π» 1. What is Shell Scripting?
In simple terms:
Shell scripting = automating commands instead of typing them one by one.
Key Points:
The shell acts as a middleman between:
π€ User
β Kernel (OS core)
Itβs a CLI (Command-Line Interface) β text-based siya, walang GUI.
π Think of it like:
Instead of doing tasks manually, you tell the computer:
βDo thisβ¦ then thisβ¦ then thisβ¦β automatically.
Real-life Example:
Instead of typing:
mkdir folder
cd folder
touch file.txtYou write a script, then boom π₯βisang run lang, tapos na.
π§ Quick Summary:
Shell = interface
Script = automation
Goal = less effort, more efficiency
π Mnemonic:
S.H.E.L.L = System Helper for Executing Logical Lines
β 2. Bash & Script Execution
Key Idea:
Bash = most common shell (Bourne Again SHell)
Script files end in.sh
Important Notes:
Scripts are executed top to bottom
Created using editors like:
vim
gedit
emacs
Basic Script Example:
#!/bin/sh
# This is a comment
echo "Hello World"Breakdown:
#!/bin/shβ start of script#β commentechoβ prints output
π§ Quick Summary:
Bash = scripting language.sh= script file
Executes line-by-line
π Mnemonic:
B.A.S.H = Basic Automation Script Handler
π 3. Names and Strings
Important Rules:
β Case-sensitive:file.txtβFile.txt
Allowed:
letters, numbers,.,_
Avoid:> < | : &
Why important?
Kasi kahit small mistake (like uppercase), error agad π
π§ Quick Summary:
Case-sensitive ALWAYS
Avoid special characters
π Tip:
βIf it looks the same to you, hindi ibig sabihin same siya kay Bash π
β
π¦ 4. Variables and Operators
What are Variables?
Storage ng data na pwede mong gamitin ulit.
Types of Variables:
Type | Meaning |
|---|---|
Local | Exists only in current script |
Shell | Built-in variables |
Environment | Accessible by child processes |
π Examples:
greetings="Hello"
echo $greetingsSpecial Example:
$BASH_VERSIONβ shows bash version
π§ Quick Summary:
Variables = storage$= ginagamit to access value
π Mnemonic:
V.A.R = Value Assigned & Reused
π’ 5. Special Variables
Super important βto kapag may arguments π
Variable | Meaning |
|---|---|
| Script name |
| Arguments |
| Number of arguments |
| All arguments |
| Last command status |
| Process ID |
π From page 2 table
π§ Quick Summary:
$= special access
Used for inputs & system info
π Mnemonic:
β$ = Special Powerβ
β¨ 6. Input & Arithmetic
Input:
read nameπ ginagamit to accept user input
Arithmetic Operators:
Operator | Meaning |
|---|---|
| Add |
| Subtract |
| Multiply |
| Divide |
| Modulo |
Example:
let a=5+3β Important:
[ $a == $b ] β [$a==$b] β
π§ Quick Summary:
read= inputlet= math
spaces matter β
π Mnemonic:
R.A.M = Read And Math
β 7. Relational Operators
Used for comparisons (numbers)
Operator | Meaning |
|---|---|
| equal |
| not equal |
| greater than |
| less than |
| β₯ |
| β€ |
π From page 3
π§ Quick Summary:
Used in conditions
Mostly inside[ ]
π Mnemonic:
βEQ = Equal, GT = Greater, LT = Lowerβ
π 8. Conditional Statements
IF-ELSE Logic:
if [ condition ]
then
command
else
command
fiπ Example from handout:
If equal β print OK
Else β ERROR
Case Statement (Cleaner Alternative)
Instead of maraming if-else π΅
case $var in
option1) ;;
option2) ;;
*) default ;;
esacParts:
caseβ start)β option;;β end case*β default
π§ Quick Summary:
IF = decision
CASE = cleaner decision
π Mnemonic:
βIF = Think, CASE = Chooseβ
π 9. Loops
For Loop
π fixed number of times
for i in 1 2 3
do
echo $i
doneWhile Loop
π runs while condition is TRUE
while [ condition ]
do
command
doneUntil Loop
π opposite ng while
Runs until condition becomes TRUE
Comparison Table:
Loop | Behavior |
|---|---|
for | fixed iterations |
while | runs while true |
until | runs until true |
π From page 4
π§ Quick Summary:
For = count-based
While = condition TRUE
Until = condition FALSE β TRUE
π Mnemonic:
F.W.U = For, While, Until
π₯ FINAL RECAP (Memory Tricks)
Alright, eto na yung quick recall cheat sheet mo:
π‘ FLOW of Shell Script:
Shell β interface
Bash β language
Script β automation
Variables β storage
Input/Operators β processing
Conditionals β decisions
Loops β repetition
π§ SUPER MNEMONIC:
π βS.B.S V.I.C.Lβ (read as: βSibs Vicel πβ)
Shell
Bash
Script
Variables
Input
Conditionals
Loops
π¬ Final Advice (Gen Z mode ON):
This part is important kasi foundation ito ng automation + Linux skills mo.
Pag gets mo βto, next level ka na sa scripting π»π₯