what is Shell Scripting for DevOps?

what is Shell Scripting for DevOps?

·

3 min read

Before we know what is shell scripting we have to understand what is kernel and shell ?

what is kernel ?

The Linux kernel is the foundation of the Linux computer operating system. A kernel is the lowest level of software that can interface with computer hardware. All Linux applications and servers also interface with the Linux kernel. All Linux distributions are based on the Linux kernel and use its services to implement various software functions

what is shell ?

A shell is a program that acts as an interface between a user and the kernel. It allows a user to give commands to the kernel and receive responses from it. Through a shell, we can execute programs and utilities on the kernel. Hence, at its core, a shell is a program used to execute other programs on our system.

what is shell scripting ?

A shell script is a list of commands in a computer program that is run by the Unix shell which is a command line interpreter. A shell script usually has comments that describe the steps. The different operations performed by shell scripts are program execution, file manipulation and text printing.

what is Shell Scripting for DevOps?

Shell scripting for DevOps enables automation of deployment, configuration management, CI/CD pipelines, monitoring, logging, and performance optimization tasks. Shell scripting languages, such as Bash, are used for automating tasks in DevOps workflows.

• What is #!/bin/bash?

`#!/bin/bash` is called a "shebang" or "hashbang." It is a special character sequence at the beginning of a script file, typically a shell script, which tells the system which interpreter to use for executing the script. In this case, `#!/bin/bash` specifies that the script should be interpreted and executed using the Bash shell.

When you run a script with a shebang, the system uses the specified interpreter to execute the script's commands. For example, if you have a Bash script and start it with `#!/bin/bash`, when you run the script, it will be interpreted using the Bash shell, allowing you to write and execute Bash commands in the script.

Different shebangs can be used for other scripting languages, such as Python (`#!/usr/bin/python`) or Perl (`#!/usr/bin/perl`), to ensure the correct interpreter is used for a particular script.

can we write #!/bin/sh as well?

Yes, you can absolutely use `#!/bin/sh` as a shebang in a script. In fact, this is a common practice. Both `#!/bin/bash` and `#!/bin/sh` are used to specify the interpreter for the script, but they refer to different shells.

- `#!/bin/bash`: This shebang specifies that the script should be executed using the Bash shell, which is a widely used and powerful shell with many features and extensions.

- `#!/bin/sh`: This shebang specifies that the script should be executed using the system's default shell, which is often a POSIX-compliant shell. It may be Bash on some systems, but on others, it could be a different shell like Dash or Bourne shell. Using `#!/bin/sh` makes your script more portable across different Unix-like systems.

The choice of shebang depends on your specific requirements. If you need Bash-specific features, use `#!/bin/bash`. If you want to ensure portability and compatibility with a wider range of systems, use `#!/bin/sh`.

• Write a Shell Script which prints I will complete #90DaysOofDevOps challenge

#!/bin/bash

echo "I will complete #90DaysOofDevOps challenge"

• Write a Shell Script to take user input .

#!/bin/bash

read name

echo "my name is ${name}"

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