Tag: Shell Script
-
Parsing arguments in shell script
I write a good amount of shell scripts, but I tend to use arguments pretty sparingly. Because of this, my implementation to handle said arguments tends to be pretty weak. Some good examples are the arguments needing to be passed in a specific order and a lack of using long…
-
Wait for open port before running command
There comes a time in every software engineer’s life, when they need to run a command, but only after a port has been opened by a completely separate process. Sure, you could sit around and wait for the port to open up before running your command, but what’s the fun…
-
Associative arrays in Bash
Arrays, both indexed and associative are a powerful and versatile data type, regardless of the language you’re utilizing them in. At one point in Bash’s history, pre-version 4.0, Bash only had indexed arrays. These indexed arrays were defined as such: # Initialize an array with values arr=(“first” “second” “third”) #…
-
Delete all files in an S3 bucket
Last year I had sunset a project that was using both AWS’ S3 and Linode’s S3-compatible object storage offering. After pulling down some final snapshots, I wanted to delete the buckets on both services. Similar to the error you receive when you attempt to rmdir a directory with files in…
-
Looping through an array in shell script
Generally speaking, when I need to work with an array or dictionary type of variable, I tend to reach for something other than Bash / shell scripting. This primarily stems from the fact that Bash didn’t support arrays until version 4.x and when I first learned about them, macOS (then…
-
Splitting a string into two variables
Even though the command-line is like my second home, I still fall short in terms of being able to some basic things. This is primarily because they just don’t come up that often so when I do figure out how to do it, I just don’t retain what I’ve learned….
-
Complete CI/CD pipeline with GitLab Runners
Automation is one of the best ways to improve productivity. Even as a development team of one, spending a bit of time on DevOps and improving your developer quality of life can pay off immensely. Automated tasks strip away cognitive load. No more forgetting to deploy code because the process…
-
Set Vim background based on your terminal’s background color
I’ve been spending more time at the pool lately (sorry, not sorry) and I’ve found myself manually switching between a light and a dark gnome-terminal theme. This was all well and good, but my .vimrc includes set background=dark so regardless of which theme I’m using in the terminal, vim has…
-
How to tell if your shell is a subshell of Vim
If you’re like me, you use Vim. If you’re like me, you use :sh[ell]. If you’re like me, you forget that you used :sh and open Vim again. I’ve been getting better about it, but every once in a while I end up with 2 or 3 nested Vim processes…
-
Temporary ufw rules or How I learned to stop scripting and love the shell
This post was originally planned to be a social commentary on the potential for riots this coming Novemeber (a/k/a The 2013 Food Stamp Riots a/k/a The Backlash of the Entitlement Society) but that seemed like such a fucking downer. Then the post was supposed to be about a Python script…