Bash Shell Scripting Fundamentals — Part 1

Photo by Christina Morillo from Pexels
Photo by Christina Morillo from Pexels

Shell was originally built to be the medium and bridge between the operating system and the user. The user can write shell command that can tell the system to do some administrative tasks.

Currently, bash shell expanded to become a full programming language — aka Shell scripting — with a lot of functionalities of programming languages such as: conditionals, loops and functions.

In this article, we will explore bash not as a terminal tool but as a programming language.

Prerequisites

To feel comfortable continuing with this article, You need some hands on work with terminal’s bash. You can check the following to catch up:

Working with shell files

Shell scripting are grouped in files that has the extension .sh . In the following video, you will be introduced to shell file by building a file duplicator program and then learn how to execute it in multiple ways.

Passing arguments & user Input

Arguments gives the bash program more details about what you need to do. Sometimes, it comes as a form of sub-command like:

yarn add <packageName> 

where “add” tells the program more about what to do, and the packageName is what data that you what to pass to the program.

You can also pass inputs in the middle of a working program. It could be asking for confirmation (y/n), authentication, etc.

In this video, we will discuss the how to of this:

Bash Variables

If you already are a programmer or a developer, then you know about variables. It’s a medium to store values in computer memory in order to use them later in the program.

Bash variables are dynamically typed. We already used them above. However, we will deep dive into how to assign a variable, how to call it, and assign a variable from a command directly.

Also, you will learn about string manipulation in bash which could get a bit tricky since we are using special characters to perform such manipulation instead of built-in functions like in other languages.

Part 1 conclusion

If you reached this far, you are now able to build very decent programs using bash script that can automate a lot of work as a developer or programmer. In part 2, we will discuss conditionals, loops and functions, so stay tuned.

Lead Software Engineer

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store