Bash Icon

Bash

Bash is a shell and command language interpreter for the GNU operating system.
20 Stories
All Topics

Bash github.com

Dead simple testing framework for bash with coverage reporting

critic.sh exposes high level functions for testing consistent with other frameworks and a set of built in assertions. One of my most important goals was to be able to pass in any shell expression to the _test and _assert methods, so that one is not limited to the built-ins.

The coverage reporting is currently rudimentary, but it does indicate which lines haven’t been covered. It works by running the tests with extended debugging, redirecting the trace output to a log file, and then parsing it to determine which functions/lines have been executed. It can definitely be improved!

See a demo of critic.sh in action on asciinema 📽️

Jeffrey Paul sneak.berlin

Stupid unix tricks

Jeffrey Paul shares a ⛴ load of goodies. I particularly like this idea:

I have a Makefile in my home directory… that I use to store common tasks related to my local machine… The one I use most often, though, is make clean, which takes everything in ~/Desktop and moves it into ~/Documents/$YYYYMM (creating the month directory in the process if it doesn’t exist), and also empties trashes.

Reader beware: 4154 words, approximately a 23 minute read

Opensource.com Icon Opensource.com

7 Bash history shortcuts you will actually use

When people see me use these shortcuts, they often ask me, “What did you do there!?” There’s minimal effort or intelligence required, but to really learn them, I recommend using one each day for a week, then moving to the next one. It’s worth taking your time to get them under your fingers, as the time you save will be significant in the long run.

Good advice on how to adopt these. Habit formation requires persistence.

Ryan Palo assertnotmagic.com

Short circuiting in Bash

Learn from Ryan Palo about the super-powers of the “short-circuit” policy in Bash.

In Bash, the && and || (AND and OR) operators work via a “short-circuit” policy.

if [[ "$1" -gt 5 ]] && [[ "$1" -lt 10 ]]; then

This checks the first condition. If the first condition is true, then there’s a possibility the whole thing could be true, so it checks the second condition. If the second condition is true, then the whole thing is true! However, if the first condition is false, then there’s no reason to check the second condition, because the whole thing could never possibly be true with the first one false.

Daniel Weibel itnext.io

macOS uses a completely outdated version of Bash

This post from Daniel Weibel not only explains how macOS uses an outdated version of Bash, but also how to upgrade to the latest Bash via Homebrew.

One thing that many macOS users don’t know is that they are using a completely outdated version of the Bash shell. However, it is highly recommended to use a newer version of Bash on macOS, because it enables you to use useful new features.

$ bash --version
GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin18)
Copyright (C) 2007 Free Software Foundation, Inc.

The reason Apple uses this old version of Bash has to do with licensing. Bash 4.0 and newer uses the GNU General Public License v3 (GPLv3), which Apple doesn’t support. There are some discussions about this on Reddit.

Version 3.2 of GNU Bash is the last version with a license that Apple is willing to accept, and so it sticks with it.

Bash github.com

A standard library and boilerplate framework for writing tools using Bash

The aim of Bash Infinity is to maximize readability of bash scripts, minimize the amount of code repeat and create a central repository for a well-written, and a well-tested standard library for bash.

It seems to me that by the time you need something as fancy/full-featured as this, maybe the task at hand has outgrown Bash? Cool, nonetheless. 👍

Bash github.com

A command-line system information tool written in bash 3.2+

The overall purpose of Neofetch is to be used in screen-shots of your system. Neofetch shows the information other people want to see. There are other tools available for proper system statistic/diagnostics.

Supports almost 150 different operating systems, so odds are it has you covered. Check my results below. Pretty decent uptime for a laptop, no?

A command-line system information tool written in bash 3.2+

Bash github.com

A collection of pure bash alternatives to external processes

The goal of this repository is to document known and unknown methods of doing various tasks using only built-in bash features. Using the snippets from this guide can help to remove unneeded dependencies from your scripts and in most cases make them that little bit faster.

I often start out with a bash script, but as soon as things get complicated I ditch it for Ruby. With this collection in hand, perhaps I can get a bit more done without throwing the baby out with the bash water.

Lazarus Lazaridis iridakos.com

How to create a bash completion script

A tutorial for adding bash completion to scripts using the bash programmable completion facilities.

Why bother?

  • to save users from typing text when it can be auto-completed
  • to help users know what are the available continuations to their commands
  • to prevent errors and improve their experience by hiding or showing options based on what users have already typed

I’m a tab-completion junkie, so the more people that know how to do this, the better!

0:00 / 0:00