DEV Community

Kengah Ireneaus
Kengah Ireneaus

Posted on

A month with bash

A Month With Bash

*this began as one long write-up but i decided to split it into three parts

A month ago I decided to learn bash so I could use my Fedora machine more effectively. My original plan was to just learn some commands and get over with it, but as I began reading resources and books, I quickly noticed how important it is for Linux users, automation experts, and system admins. The thing that amazed me most is that I could literally automate almost every repetitive process I do on my PC.

Getting Started

Starting off with bash wasn't really bad or difficult, maybe because I already had experience programming in C and Python. Learning the basic syntax of bash wasn't much of a problem — things like variables and printing to the terminal were quite easy to grasp. I also learned some theory on shell types and their differences, which wasn't too hard either.

# create, assign, and print a variable
my_var="declared"
echo "$my_var"
Enter fullscreen mode Exit fullscreen mode

Moving Deeper Into Bash

After the basics, where bash just seemed like a small programming language, things changed once I started learning about the bash environment. This is what began to show me what makes it special and unique. I learned about:

  • Shell initialization scripts
    • System-wide
    • Individual user scripts
    • How to configure them

Honestly, these files affect system behavior, so it's better to avoid touching them unless you know what you're doing. This part was quite confusing at first, but with practice it became clearer. I still don't fully understand every use case of these initialization scripts off-hand, and explaining them isn't the goal of this post.

After that I took some time to learn about reserved variables — just a curated table of them. They're very useful because they enable some handy functionality, and they're good to use when making a script portable. Some important ones:

  • HOME
  • IFS
  • PWD
  • PATH
  • DIRSTACK
location="$HOME" # this stores the location of the home directory
echo "$location"
Enter fullscreen mode Exit fullscreen mode

Next up: special parameters, expansions, and how bash actually executes a script line by line.

Top comments (0)