As a part of a series of learning DevOps one must understand the importance of Linux and shell Scripting.
Shell - Shell refers to a program that provides a command line interface for interacting with an Operating system.
What is Shell Scripting in DevOps?
Shell Scripting is important in DevOps as it helps in the automation of day-to-day activities such as software development and deployment. An application running on top of the kernel and provides a command line interface to the system. so, a shell script is plain text that contains the command that a shell interpreter can execute.
There are several shells available for Linux -
Bash (Bourne Again Shell) - Is one of the most commonly used UNIX/LINUX shells and it is the default shell in many Linux distributions.
CSH (C Shell) - C shell's usage is similar to C programming language.
KSH ( Korn Shell) - It is also known as POSIX shell, which allows you to create aliases to customize commands.
What is #!/bin/bash?
#!bin/bash is called shebang line which use to instruct the computer to use a command interpreter when running the script.
#!/bin/sh - It is a system's default shell, depending on the system it can be bash or a different compatible shell.
Note - #!/bin/bash has more advanced features than #!/bin/sh.
You can find a basic example of shell scripting below for your reference.
Write a Shell Script that prints
I will complete #90DaysOofDevOps challenge
You can run a bash script from the terminal or by executing any bash file.
Run the following command from the terminal to execute a very simple bash statement. The output of the command will be "I will complete #90DaysOofDevOps challenge"
.
Write a Shell Script to take user input, input from arguments, and print the variables.
Below command will get the user input(username) from the argument.
The output of the command will print the variables.
Write an Example of If else in Shell Scripting by comparing 2 numbers
-gt. This stands for “greater than”.
The command output compares the 2 numbers and displays the output using if-else statements.
I hope you enjoyed this guide on learning Shell scripting for DevOps engineers.
Happy Learning!