Skip to content

EngineeringSoftware/gobash

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gobash

test (bash 3) test (bash 4) test (bash 5) test (mac) lint

gobash is a set of functions that improve programming experience in bash (by providing collections, structs, methods, APIs, testing package, command line flag parsing, etc.) without modifying the shell interpreter(s). It works with any bash version (on Linux and Mac). Parts of the API are matching those in Go.

For more information about gobash, see the main documentation page: http://gobash.org.

API documentation is available here.

If you love learning by example, take a look at the examples page. A quick demo of the very basic concepts using a toy example is available here.

Key Features

We focused on a design that enables the following key features (discussed in more detail at gobash.org):

  • Programming language features - gobash enables (via functions and files) defining structs and methods and instantiating "objects", e.g., example
  • Arguments and return values - gobash supports passing "objects" as arguments to functions and returning them as "out" arguments, e.g., example
  • Collections - gobash (using structs) provides a flexible collections: Lists and Maps (thus avoiding built-in structures when they are not sufficiently flexible or they are not available in old versions), e.g., example
  • Command line flag parsing - gobash introduces a set of functions for parsing command line flags (similar to those in other programming languages), e.g., example
  • Testing - gobash comes with a testing package, e.g., example
  • API - gobash provides a set of functions to support common tasks and abstractions, such as strings, Mutex, Chan, e.g., example

A Quick Example

#!/bin/bash

# Import the library.
source /dev/stdin <<< "$(curl https://raw.githubusercontent.com/EngineeringSoftware/gobash/main/hsabog 2>/dev/null)"

# Create a communication channel.
ch=$(Chan)
# Send a message (blocking call) in a sub process.
( lst=$(List 2 3 5); $ch send "$lst" ) &

# Receive the message (blocking call) in the main process.
lst=$($ch recv)

$lst to_string
# Output:
# [
#   "2",
#   "3",
#   "5"
# ]

Dependencies

gobash uses several bash builtins, GNU coreutils, and binaries widely available on Unix. Although the repository keep changing, the list probably includes jq, sed, grep, awk, date.

Versioning

gobash was tested on Linux with the following bash versions:

gobash bash 3 bash 4 bash 5
1.0.1-dev 3.2.57 4.4.18 5.0.17

We also test on Mac. Please see the CI runs for details and up-to-date information.

(gobash versions prior to 1 were internal releases. Once we stabilize API or someone starts using the library, we will make public releases.)

Acknowledgments

I would like to thank Ahmet Celik, Owolabi Legunsen, Darko Marinov, Pengyu Nie, and Aditya Thimmaiah for years of joint fun with bash. Also, I would like to thank Aleksandar Milicevic for his feedback on this project.

License

BSD-3-Clause license.

Contact

Feel free to get in touch if you have any comments: Milos Gligoric <milos.gligoric@gmail.com>.