Shell Scripting
Shell scripting is like giving your computer a to-do list written in a special text file known as a shell script. It's a way to tell your computer what tasks to perform using the Linux operating system. Think of a shell as a helpful assistant that lets you talk to your computer.
In Linux, the most popular assistant is called the bash shell – it's like your computer's personal helper, built on the Bourne shell¹.
Why is shell scripting cool?
Easy to Use: It's like using the same magic words when talking directly to your computer in the command line.
Saves Time: Imagine your computer doing those repetitive tasks for you, making fewer mistakes than humans.
Superpowers for Your Shell: You can create special commands and features, adding new tricks to your computer's toolkit.
Now, when you write a shell script:
Shebang: It's like saying, "Hey, computer, get ready to follow my instructions!" with a line that looks like
#!/bin/bash
.File Extension: It can end in .sh, but it's okay if it doesn't.
Permissions: You just need to tell your computer it's okay to follow your script with
chmod +x script.sh
.Arguments: You can give your script information when you run it, like names or numbers.
Variables: These are like containers where you can store information. Create them using
=
and use them with$
.If Statements: This is where you tell your computer to do something only if certain conditions are met. It's like giving your computer a decision-making power.
See below a simple shell Script:
Start by creating a shell file using any preferred editor but in this case, I am using “VIM”
Write out the shell script as seen below
Change the permission on the script to allow execution
Execute the shell script and as we can see, the result of the script “Hello World” is displayed below as we used “echo” which simply means to print.
Below is another shell script that calculates your age to tell if you are an adult or not:
To make the learning seamless for you, I have created a repository on GitHub where I will be dropping shell scripting project ideas for you to learn and also some documentation that will ease your learning phase.
Follow me on my GitHub
Here is the GitHub Repo where I will be dropping Shell Scripting ideas for hands-on practice. Feel free to star the repository if you find it helpful.