DEV Community

Cover image for BASHing through the terminal
Jose Ross Barredo
Jose Ross Barredo

Posted on

BASHing through the terminal

My fascination with Bash Shell Scripting started just 3 months ago. Prior to that, I never had any knowledge with what and how to bash. It has proven to be a powerful tool to help you automate basic routine tasks.

My first encounter with bash was when my lead developer told me to create a simple cronjob to execute a SQL script to import into the database. With limitations from the SQL like variable value replacement from a random source, SQL just couldn't do the job. That is when I "discovered" bash shell scripting. From then on, my journey with bashing through the terminal started.

As a UNIX Linux user, I do basic shell commands like ls, sudo or cd. I know just the ordinary commands from my bachelors but never have I thought you could do all sorts of basic algorithm constructs just like how a programming language would from handling files, array declaration, string replacement and down to looping, conditional statements and the like.

Learning to Bash, by bash I mean shell scripting, is intimidating but it is actually easy than it looks. Though, I must say developers with limited programming background might not be for bash. Learning Bash has a shallow learning curve.

Shell scripting allows us to extensively use the shell's abilities and automate a lot of tasks that would otherwise require long and complicated commands. It really does save time when you automate routine tasks like monthly backup compression or SQL import.

This article is the first part to my Bash tutorial posts. I hope you will not only enjoy but also will learn a thing or two from my Bash Shell Scripting tutorials soon.

But before you go, have you used Bash Shell Scripting yourself?

Discussion (8)

Collapse
ferricoxide profile image
Thomas H Jones II

Being heavily invested in shell scripting sometimes makes it hard to shift gears to other "real" languages. Haven't really found much, yet, that I can't accomplish more quickly in a shell script (due to the reflexive nature of same) ...And have also had a lot of people look at my shell code and remark, "I didn't know all of that could be done in shell scripting."

Collapse
iamjoross profile image
Jose Ross Barredo Author

Would you say then that shell scripting is a beneficial "language" to learn? I have read blog posts saying that learning to shell script is a waste of time.

Collapse
ferricoxide profile image
Thomas H Jones II

Depends on what you're doing. If you ever need to do OS-level tasks (rather than pure application-development), then it's foolish not to learn how to automate and optimize the execution of those tasks.

Collapse
radio_azureus profile image
Radio Azureus

I work in bash since the dawn of #Linux

Collapse
iamjoross profile image
Jose Ross Barredo Author

Wow! How often do you use bash and for what tasks?

Collapse
radio_azureus profile image
Radio Azureus

Reference link <dev.to/radio_azureus/comment/a5pb>

I use bash over the whole gamut, from simple tasks as managing files & directories in ~ to (simple) programming & scripting where it is just vital to have a shell you are comfortable in.

There are many flavors of shells, so you will also meet people who love #csh #ksh #zsh (had this on my Amiga) #ash #sh (the original Bourne shell)

Whatever OS I'm in, I install git, since it also has git bash in case you are on an OS which has no bash installed.

This is an example of how I use git to manage markdown files all via bash
<imgur.com/N3HDHMG>

I can easily move to another workstation and OS. Then I can pickup where I left off transparently as if nothing happened.

I could also sync my ~/.bash_history via my network, if needed instead of ssh-ing to the machine to peek into the file to lookup a complex ssh tunnel pipe I've forgotten the exact syntax to.

Since I also spawn all executable from the shell ever since the #c64 & #amiga computer era (Amiga CLI), I have a shell open whenever my workstation runs. In case of this #DAW it's 24/7

On servers and workstations I basically live in $bash

()#DAW -> digital audio workstation

Collapse
vishwakarma09 profile image
Sandeep Kumar

Like when working on nose project. Or when on working on python security modules like sqlmapper

Collapse
denisrasulev profile image
Denis Rasulev

Using bash for some basic staff, like moving around directories, scp-ing files to/from my VPSs, crontabing some basic regular operations, logs checking etc. Would love to upgrade my level of bash :)