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 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 | |||||||||||||||||||||||||||||||||
π Mnemonic: β¨ 6. Input & ArithmeticInput:π ginagamit to accept user input Arithmetic Operators:
Example:β Important: β [a==$$b] β π§ Quick Summary:
π Mnemonic: β 7. Relational OperatorsUsed for comparisons (numbers)
π From page 3 π§ Quick Summary:
π Mnemonic: π 8. Conditional StatementsIF-ELSE Logic:π Example from handout: Case Statement (Cleaner Alternative)Instead of maraming if-else π΅ Parts:
π§ Quick Summary:
π Mnemonic: π 9. LoopsFor Loopπ fixed number of times While Loopπ runs while condition is TRUE Until Loopπ opposite ng while Comparison Table:
π From page 4 π§ Quick Summary:
π Mnemonic: π₯ FINAL RECAP (Memory Tricks)Alright, eto na yung quick recall cheat sheet mo: π‘ FLOW of Shell Script:
π§ SUPER MNEMONIC:π βS.B.S V.I.C.Lβ (read as: βSibs Vicel πβ)
π¬ Final Advice (Gen Z mode ON):This part is important kasi foundation ito ng automation + Linux skills mo. |