Most of us in CS-348 have been introduced to the terminal and bash scripting from previous classes or using Linux on their laptop. I haven’t used linux for any major projects but I installed and dual boot linux on my laptop (windows and linux installed on two different ssd) and use it for small side projects, or to learn new things. It’s for this reason I use a laptop that’s a little bit older so that everything inside is easily accessible and I can modify it however I like. The terminal allows a user or programmer to control their computer and make requests to the OS through keyboard commands rather than interacting with the user interface. One advantage with using the command line vs GUI is it keeps a history log of every command that was executed which makes doing things again much quicker and more organized, and it helps if you need a reminder for what you did a few days ago. You can type individual commands in the terminal prompt one at a time or you can write a bash script, which is a text file with the .sh extension that contains multiple bash commands to be executed at once.
How and what do programmers do with bash scripts exactly? I found this blog post to be a great introduction for programming students like myself to practice, with tasks that relate to real IT jobs we may hold one day: https://linuxhandbook.com/bash-automation/. The bash is a great tool for running tasks that are boring and repetitive without much repeated effort. The first example shows how a system administrator can use a bash script to create a new user on multiple servers. This example shows how you can even use bash scripts to enter data from the command prompt and use this data to create the new user. The third example shows how you can monitor disk space using a bash script and send an email warning whomever is using the computer that disk space is running low and by how much. These are basic examples that show how simple bash scripts can save you a lot of time in the long run.
Bash scripting is something most of us will come across at some point in our programming careers and it’s important to get a handle on the basics. Automating mundane tasks will make work easier and show you have a wide variety of skills.
From the blog CS@Worcester – Site Title by lenagviaz and used with permission of the author. All other rights reserved by the author.