# Day -04 #90daysofdevosp

## **What is shell Scripting?**

Shell scripting is the practice of writing and executing a series of commands in a shell (command-line interpreter) to automate tasks, perform system administration, or run a sequence of operations. The shell is a program that acts as an interface between the user and the operating system, allowing users to interact with the computer's resources through commands.

## What is Shell Scripting for DevOps?

Shell scripting for DevOps refers to the use of shell scripts to automate various tasks and processes in the context of DevOps practices. DevOps is a set of practices that aim to improve collaboration and communication between software development and IT operations teams, to deliver applications and services more quickly and reliably.

In Unix-like operating systems (such as Linux and macOS), the most common shell is the Bourne shell (sh), also called as Bourne-Again Shell (bash), the Korn Shell (ksh), the Z Shell (zsh), and others. In Windows, the primary shell is the Command Prompt (cmd.exe)

## What are the Benefits of Shell Scripting in Devops?

Shell scripting plays a crucial role in DevOps and offers several benefits that contribute to efficient and streamlined software development, deployment, and operations.

* **Automation**: Shell scripts are used to automate various tasks, such as building, testing, and deploying applications. By automating repetitive processes, developers and operations teams can save time and reduce the risk of human errors.
    
* **Infrastructure as Code (IaC)**: Shell scripts can be used to define and manage infrastructure configurations, making it easier to provision and manage resources in cloud environments or on-premises.
    
* **Easy Integration**: Shell scripts can integrate with other tools and services commonly used in the DevOps workflow, such as version control systems, continuous integration/continuous deployment (CI/CD) pipelines, and monitoring tools.
    
* **Customization**: DevOps environments often have unique requirements. Shell scripting allows teams to create custom scripts tailored to their specific needs and workflows.
    
* **Portability**: Shell scripts are typically platform-independent, allowing them to run on various operating systems and distributions. This portability is beneficial for heterogeneous environments.
    

# What is `#!/bin/bash?` can we write `#!/bin/sh` as well?

The shebang, #!/bin/bash when used in scripts is used to instruct the operating system to use bash as a command interpreter. Each of the systems has its own shells which the system will use to execute its own system scripts. This system shell can vary from OS to OS(most of the time it will be bash). Whereas, when the shebang, #!/bin/sh used in scripts instructs the internal system which may vary depending upon the operating system it can be bash, ksh, dash, zsh etc.

## Write a Shell Script that prints `I will complete #90DaysOofDevOps challenge`

Shell Script:

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1689711589537/d54c2093-e164-4c4d-9388-7c774247ac92.png?auto=compress,format&format=webp align="left")

Output:

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1689711748195/1c2f6251-a565-4e77-8c5d-b73bc197abf2.png?auto=compress,format&format=webp align="left")

## Write a Shell Script to take user input, input from arguments and print the variables

Shell Script:

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1689712464900/4e792bcb-b7d0-4992-be66-9c96f4e6ce56.png?auto=compress,format&format=webp align="left")

Output:

`hello Vaishnavi welcome to DevOps`

## Write an Example of If else in Shell Scripting by comparing 2 numbers

Shell Script:

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1689711844428/3f4c76b3-4fa8-461a-88ac-ef5122a78751.png?auto=compress,format&format=webp align="left")

Output:

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1689711978321/6709897a-0537-48a7-a915-a5c625d5bcb8.png?auto=compress,format&format=webp align="left")

> ***Thanks for watching my blog.***
