Basic of Linux Shell Scripting for DevOps Engineers. #90DaysOfDevOps Challenge - Day 4
In this article I try to explain the importance of shell scripting in automation, list of arithmetic operator , if else condition in shell scripting

Tasks
1 Explain in your own words and examples, what is Shell Scripting for DevOps.
2 What is
#!/bin/bash?can we write#!/bin/shas well?3 Write a Shell Script which prints
I will complete #90DaysOofDevOps challenge4 Write a Shell Script to take user input, input from arguments and print the variables.
5 Write an Example of If else in Shell Scripting by comparing 2 numbers.
What is shell scripting for DevOps?
Before that, we should know the architecture of Linux.

Shell Script
The script in which various shell commands are there is called a shell script
Shell interacts with kernel and kernel with hardware. This script runs on a shell.
kernel:
The kernel is the core component of an operating system, with complete control over everything in the system. This provides a platform for programs and various services to run on top of it.
It manages the following resources of the Linux system –
- File management, Process management, I/O management, Memory management, Device management etc.
Shell: A shell is a special user program that provides an interface for the user to use operating system services. Shell accepts human-readable commands from users and converts them into something which the kernel can understand.
It is a command language interpreter that executes commands read from input devices such as keyboards or from files. The shell gets started when the user logs in or starts the terminal.
Shell can be accessed by users using a command line interface. A special program called Terminal in Linux/macOS, or Command Prompt in Windows OS
Terminal:
A program that is responsible for providing an interface to a user so that he/she can access the shell. It allows users to enter commands and see the output of those commands in a text-based interface. Large scripts that are written to automate and perform complex tasks are executed in the terminal.

- so now we will discuss what is shell scripting for DevOps
Shell scripting for DevOps refers to the practice of writing scripts using shell languages (such as Bash, PowerShell, or Python) to automate and streamline various tasks and processes in the context of DevOps practices. DevOps aims to improve collaboration and integration between development and operations teams, focusing on automating and accelerating software delivery, infrastructure provisioning, and system maintenance.
Shell scripting plays a crucial role in DevOps by allowing developers and operations personnel to automate repetitive tasks, manage infrastructure, and deploy and maintain applications. These scripts can be used to perform a wide range of operations, including:
Build and deployment automation: Shell scripts can automate the build and deployment processes, integrating with version control systems, packaging applications, and deploying them to various environments.
Configuration management: Scripts can be used to automate the configuration of servers and infrastructure, ensuring consistent and reproducible setups across different environments.
Continuous integration and continuous deployment (CI/CD): Shell scripts can be used to define and orchestrate the CI/CD pipeline, including tasks such as running tests, building artifacts, deploying to staging or production environments, and performing post-deployment validations.
Provisioning and infrastructure management: Shell scripts can interact with cloud providers' APIs or infrastructure-as-code tools (such as Terraform) to automate the provisioning and management of cloud resources and infrastructure.
Log analysis and monitoring: Scripts can process and analyze log files, generate reports, or trigger alerts based on specific conditions, facilitating proactive monitoring and troubleshooting.
Data migration and database management: Shell scripts can automate data migration tasks, database backups, replication, and other database management operations.
By leveraging shell scripting for DevOps, teams can reduce manual effort, increase efficiency, ensure consistency, and minimize human errors. These scripts provide the flexibility to customize and extend automation workflows, making them an essential tool in the DevOps toolkit.
Q.2 What is #!/bin/bash? can we write #!/bin/sh as well?
The line #!/bin/bash is known as a shebang or hashbang, and it appears at the beginning of a shell script file. It is used to specify the interpreter or shell that should be used to execute the script.
In this case, #!/bin/bash specifies that the script should be interpreted and executed by the Bash shell. Bash (Bourne Again SHell)(updated version of shell) is a widely used shell and the default shell for many Unix-like systems, including Linux.
Alternatively, you can use #!/bin/sh as the shebang to specify the generic Bourne shell. The Bourne shell(old one) is the original Unix shell and is available on most Unix-like systems. Although Bash is backward-compatible with the Bourne shell, it includes additional features and enhancements. If your script only uses features supported by the Bourne shell, using #!/bin/sh ensures portability across different Unix-like systems.
However, it's important to note that if you use Bash-specific features in your script and specify #!/bin/sh as the shebang, the script may not work as expected on systems where /bin/sh points to a different shell that lacks those features.
In general, if you are writing shell scripts intended to run on a specific system where Bash is available, it is common to use #!/bin/bash to take advantage of Bash's additional features. If you need to write portable scripts that work on a wider range of systems, you may opt for #!/bin/sh and ensure that your script adheres to the subset of features supported by the Bourne shell.
Q3 Write a Shell Script that prints I will complete #90DaysOofDevOps challenge
first we create the directory with a name "new" and then in this dir create a file name challenge.sh === >to run shell script we create .sh file extension. here we are using vim editor .


you can write any message in the echo command echo "---------"
After that, we change the file permission with chmod command and run the shell script with ./ (dot slash)

so you can see the message {I will complete the #90daysof challenge } in the above screenshot.
Q4 Write a Shell Script to take user input, input from arguments and print the variables.
Here we create a file script.sh like in the below pic. using vim command and
try to use command line argument.


Permit to execute the file by chmod 700 command

Now running the script by ./script.sh
To use this script, you can run it with the desired filename as a command-line argument, like this:

Here is a list of other arithmetic operators that you can use in your Bash script.

Q5 Write an Example of If else in Shell Scripting by comparing 2 numbers
Type the command


and change the file permission to execute by chmod 700 cmmand

now run the file by ./




