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 ๐ป๐ฅ