Day-04 Basic Linux Shell Scripting for DevOps


What is Shell Scripting for DevOps?
Shell scripting is a fundamental skill in DevOps, which is a set of practices that combine software development (Dev) and IT operations (Ops) to automate and streamline various aspects of the software development and delivery process. In DevOps, shell scripting involves writing and executing scripts in a shell (like Bash) to automate routine tasks, manage infrastructure, and facilitate continuous integration and continuous delivery (CI/CD) pipelines.
Here are some key aspects of shell scripting in DevOps:
Automation: Shell scripts are used to automate repetitive and manual tasks. For example, you can write scripts to automatically deploy applications, provision and configure servers, or manage cloud resources.
Infrastructure as Code (IaC): Shell scripts can be a part of Infrastructure as Code practices. They help define and manage infrastructure by scripting the setup and configuration of servers, networks, and other resources.
CI/CD Pipelines: Shell scripts are often used in CI/CD pipelines to build, test, and deploy applications automatically. They help ensure a consistent and repeatable deployment process.
Monitoring and Logging: Shell scripts can be used to collect, analyze, and act upon system logs and metrics. They help in maintaining system health and diagnosing issues.
Configuration Management: Shell scripts assist in managing configuration files and ensuring that systems are correctly configured.
Security and Access Control: Shell scripts can be used to enforce security policies and manage user access to systems.
What is #!/bin/bash
& #!/bin/sh
?
#!/bin/bash
is called a "shebang" or "hashbang." It's a special line that you put at the beginning of a script file in Unix-like operating systems (including Linux). It tells the system which interpreter to use to execute the script. In this case, it specifies that the script should be interpreted and executed by the Bash shell.
You can also use #!/bin/sh
in the shebang line to specify that the script should be executed using the system's default Bourne shell. This is more generic because it relies on the system's configured shell, which may or may not be Bash. Bourne shell scripts tend to be more portable across Unix-like systems.
If you want to use specific features or syntax unique to Bash, you would use #!/bin/bash
.
If you want to write a more portable script that's likely to work on a wider range of Unix-like systems, you can use #!/bin/sh
.
Many systems symlink /bin/sh
to a specific shell, which could be Bash, Dash, or another compatible shell. So, using #!/bin/sh
is generally a safer choice for portability.
How to write a Shell Script which prints
I will complete #90DaysOofDevOps challenge
Write a Shell Script to take user input, input from arguments and print the variables.
- User Input :
User Input from Argument :
Write an Example of If else in Shell Scripting by comparing 2 numbers
Subscribe to my newsletter
Read articles from Irfan S Momin directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Irfan S Momin
Irfan S Momin
A Foodie Software Engineer's Journey to Eating Healthy and Learning Something New Every Day