DEV Community

Amanda Igwe
Amanda Igwe

Posted on

Day 27/ 30 Days of Linux Mastery: Introduction to Shell Scripting

Table of Contents


Introduction

Welcome back to Day 27 of this practical Linux challenge!

If you have been following my articles and practicing your commands on RHEL 9, then you are already using the shell!

Now, imagine having the shell perform multiple tasks for you automatically. That is what shell scripting is all about.


What is Shell Scripting?

A shell is a command-line interpreter that lets you interact with the operating system. Shell scripting is the process of writing a series of shell (command-line) instructions in a file that can be executed like a program.

Think of it like creating your own little tool to automate boring or repetitive tasks!

With it, you can:

  • Automate backups
  • Monitor system performance
  • Create users
  • Set scheduled tasks
  • Parse logs
  • Deploy services

Types of Shells

Linux systems support several types of shells. The most commonly used ones include:

Shell Description
sh The original Bourne shell. Simple, but limited.
bash Bourne Again Shell – the most widely used and powerful shell on Linux (and the default on RHEL).
zsh Z shell – known for features like auto-completion and customization.
ksh Korn shell – used in enterprise environments.
fish Friendly interactive shell – user-friendly and great for beginners.

For this tutorial, we will use bash, as it is the default on RHEL 9.


Real-World Scenario: Shell Scripting

Let's create and run our first shell script.

  • Open your terminal, create a file and this line into it
vim hello.sh   # note that script files end with a .sh

#!/bin/bash    # this is called shebang /bin/bash must always start the line in every script you are writing


echo "Hello, world! This is Amanda's first shell script in RHEL 9!"    # echo prints the message as an output on your terminal.

# Save and exit using:wq!
Enter fullscreen mode Exit fullscreen mode

wm1 description

  • Now, give the script permission to run
chmod +x hello.sh     # this enables it to be executable
Enter fullscreen mode Exit fullscreen mode

wm3 description

  • Verify the file has the execute permissions
ls -ltr hello.sh
Enter fullscreen mode Exit fullscreen mode

wm4 description

  • Run the script on your terminal
./hello.sh
Enter fullscreen mode Exit fullscreen mode

wm5 description


Conclusion

Shell scripting might sound scary at first, but once you try it, you will wonder why you didn’t start sooner. Even with just 3 commands, you can automate tasks that make your life easier.

In RHEL 9, this is one of the most useful beginner skills. Just remember: start simple, run often, and break things (on purpose lol).

See you in the next article, where we dive deeper into shell scripting!

If this is helpful to you, feel free to bookmark, comment, like and follow me for Day 28!


Let's Connect!

If you want to connect or share your journey, feel free to reach out on LinkedIn.
I am always happy to learn and build with others in the tech space.

#30DaysLinuxChallenge #Redhat#RHCSA #RHCE #CloudWhistler #Linux #Rhel #Ansible #Vim #CloudComputing #DevOps #LinuxAutomation #IaC #SysAdmin#CloudEngineer

Top comments (2)

Collapse
 
nevodavid profile image
Nevo David

been cool seeing steady progress - it adds up. you think the consistency or just the daily practice is what actually sticks long run?

Collapse
 
amandaigwe profile image
Amanda Igwe

I think both the daily practice and consistency works hand in hand. Personally, both gave me good habits.