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. |