Shell Scripting - Automate Like a Cyber Samurai
Welcome, young cyber-samurai! 🥷💻
Tired of typing the same boring commands every day? Want to automate tasks like a true hacker ninja? It's time to unleash the power of shell scripting – the ancient art of automation!
Shell scripting turns you into a cyber-samurai, slicing through repetitive tasks with just a single command.
What is a Shell Script?
A shell script is simply a text file filled with commands that you’d normally type in a terminal. Instead of repeating commands, you write them once and let the computer do the work for you. 🖥️
💡 Think of it as writing a to-do list for your terminal. Instead of saying:
cd /var/www
ls -lah
cp config.php config_backup.php
You put those commands in a file and run it like a digital magic spell! ✨
Creating & Running Your First Script
🔹 Step 1: Create a new script file
nano mynoobscript.sh
🔹 Step 2: Write your script (inside mynoobscript.sh
)
#!/bin/bash
# The ancient words of greeting
echo "Konichiwa, Cyber Samurai! 🥷"
# Display today's date
echo "Today's date is: $(date)"
# Show system uptime
echo "Your machine has been running for: $(uptime -p)"
🔹 Step 3: Make the script executable
chmod +x mynoobscript.sh
🔹 Step 4: Run your script like a true ninja!
./mynoobscript.sh
🎉 Boom! Your script runs like a boss! 🤯
Understanding the Magic
Symbol | Meaning |
---|---|
#!/bin/bash | 🏯 Tells the system to use the Bash shell |
echo | 💬 Prints text to the terminal |
$(command) | ⚡ Runs a command inside another command |
chmod +x | 🔓 Makes a script executable |
Pro Tip: Without chmod +x
, your script is just a boring text file. Don't forget it! 😎