Basic Linux Shell Scripting for DevOps
For aspiring DevOps engineers, it is essential to know shell Scripting or bash scripting. In this shell scripting for DevOps guide, I will share my tips & resources to learn Linux shell scripting the right way.
TABLE OF CONTENTS
Shell Scripting for DevOps
Shell script is very important for DevOps person.shell script comes in handy for repeatable development tasks. For example, it could be spinning up a Vagrant VM with the essential software or setting up the development environment itself.Most importantly, hands-on scripting and programming are becoming mandatory in preliminary interview rounds in DevOps interviews. So it is another crucial reason why you should learn shell scripting.
How to Get Started With Shell Scripting?
The prerequisite to getting started with shell scripting is hands-on experience with Linux. Therefore, before getting started with shell scripting, you should have basic knowledge of linux commands.
If you are totally new in Linux so I would suggest first learn basics of Linux then jump on next step, once you get comfortable with linux you can get start with shell scripting.
Shell Scripting Languages
First of all, there are no specific shell scripting languages. When it comes to shell scripting, it refers to sh, bash, csh, tcsh
. Here we are primarily talking about bash shell scripting. Bash is an interpreted scripting language for Unix-based systems.
But scripting languages, in general, means multiple languages. The following are the common scripting languages.
Powershell
Python
Pearl
Groovy
Shell Scripting DevOps Interview Questions
Shell scripting DevOps interview questions differ from company to company.
For example, a Service based company would be just interested in your basic Linux and shell scripting knowledge. However, a product-based company might expect a good level of knowledge in Linux command line and shell scripting.
Nowadays, most companies would provide platforms like Hackerank to test your scripting skills. So it is necessary to practice shell scripting to solve problems.
Following are some of the DevOps interview shell script questions.
Shell script to reverse a string
Parse a log in desired format and find all occurrence of a word
Shell script to send the first ten lines of a file to another file.
Merge(contatinate) two files and write the output to the third file.
Find all duplicate strings in a file and replace it with another string
Find all the IP adress from a log file and write it to another file.
I will be updating the list with more generic interview questions soon.
Shell Scripting FAQ’s
Following are some of the frequently asked shell scripting questions by aspiring DevOps engineers.
How hard is it to learn Linux shell scripting?
Learning shell scripting is like learning any other technology. If you have a good foundational knowledge of Linux, you can learn shell scripting easily, provided you follow a disciplined learning path.
Is scripting required for DevOps Engineers?
Yes. Scripting knowledge is very essential for a DevOps engineer. For the development environment till production, a DevOps engineer might have to create useful utilities using scripting.
Which scripting language is best for DevOps?
It depends on the project. But Bash, Powershell, and python are the commonly used scripting languages in DevOps-based projects. Groovy is essential if the project uses Jenkins.
Is Shell Scripting used for automation?
With the advent of many DevOps tools, there is no need to write full-fledged automation in shell scripts. However, shell scripts are used as part of those automation tools to support a few functionalities. A classic example would be using shell scripting with Hasicorp Packer to build VM images.
Conclusion
I hope you enjoyed this guide on learning Shell scripting for DevOps engineers.
Now I’d like to hear from you: Which method or resource from today’s guide are you going to try first?
Are you going to start with the Linux basics? Or start focusing on interview-based questions
Let me know by leaving a quick comment below right now.