Basic Linux Shell Scripting for DevOps Engineers

Photo by Luca Bravo on Unsplash

Basic Linux Shell Scripting for DevOps Engineers

What is Shell Scripting for DevOps

Shell Scripting is a commonly used tool for automating and managing various tasks and processes. The benefits of shell scripting include increased efficiency, reduced errors, improved consistency, and the ability to quickly respond to changing requirements. Shell scripting also helps DevOps practitioners scale their operations as needed.

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

#!/bin/bash is called a "shebang" AKA "hashbang" line. It is the 1st line of a shell script. This declares to the system that this is a "script".

#!/bin/bash (Bourne Again Shell) states that this script is running on a Bash Shell interpreter. It is commonly used on Linux and MacOS. #!/bin/sh (Bourne Shell) is a commonly used shell in Unix-based operating systems.

Shell Script which Prints my 90 days of DevOps Challenge statement

A file 1st needs to be created. You can either use "touch" or directly create a new file by accessing the VIM editor. Once created & saved, I will change the file property via chmod command for executing permission before running the file using the ./ command.

In VIM Editor "shebang" was declared. I used "i" to edit, echo for my challenge statement, and ":wq" used to write & quit the file.

I used the chmod command to change the file permission to make sure it's executable. Once a file is executable, the color changes to green. In a future blog, I will share more information on file permissions. ./ was used to run the script file "devops_challenge.sh".

Shell Script to take user input, input from arguments and print the variable

I created this script file "user_input.sh". User will be prompted to enter their name in a variable, which will then display the variable with the statement - keeping it simple.

If else-if & else in Shell Scripting by comparing 2 numbers

When first coming across this, it took a bit of time to understand this, but what made it easier was to write out what I'm looking to achieve. After that, I reviewed my notes, and see some examples of understanding how if-else works and this task became much easier to complete. I used if, else-if, & else to compare 2 numbers entered by the user. I used "-eq" for equality check and "-lt" for less than. There are several ways how this script could have been written.


I appreciate your busy time reading this short blog. As I continue with my journey to learn and acquire the skill set of a DevOps Engineer, I will share what I learn. Thank you.

Happy Learning!


Sam Samarullah

LinkedIn

Previous Blog

Instagram