Skip to content

bwvoss/_bash

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

_BASH

================

Enumerable functions for bash scripting

Motivations

Bash is a great tool for many jobs. I find myself using it most for server administration and workspace customizations.

As others have noted shell scripting can be incredibly powerful, yet is commonly neglected in preference of higher level langauges.

When I started shell scripting, I found myself wanting to reach for many enumerable functions. This project is an attempt to help provide bash scripters with enumerable functions to be more productive right away, and have more fun developing readable scripts.

Everybody has their own -- usually difficult to decipher -- flavor of how to implement a solution. Want to know how the code should look see if an array contains an element? Check out the difference in opinion and style in this stackoverflow post

Design Considerations

Strings vs Globals

Avoiding eval

Streams and Pipes vs Globals

Current Support (for arrays only)

contains
list=("this" "that" "to_find")

_contains list[@] "to_find"
=> 0

_contains list[@] "not here"
=> 1
map
numbers=(1 2 3)

add_one() {
  echo $(($1 + 1))
}

($(_map numbers[@] add_one))
=> (2 3 4)
size
list=()

_size list[@]
=> 0

populated_list=(1 2 3 4 5 6 7 8)

_size populated_list[@]
=> 8

Installation

$ git clone
$ cd _BASH

#First argument is where to install the bin to
#Second argument is the dotfile you'd like it sourced from
$ ./install /usr/local/bin ~/.bash_profile

Testing

All testing is done with bats, can be found in the test directory and can be run with:

./run_tests

or

bats <path-to-test-file>

Development

Collections (arrays and associative arrays):

  • each
  • map
  • reduce
  • find
  • filter
  • reject
  • all
  • any
  • max
  • min
  • sort
  • group

Array specific:

  • first
  • initial
  • last
  • rest
  • compact
  • flatten
  • without
  • union
  • intersection
  • difference
  • uniq
  • zip
  • unzip
  • index_of
  • find_index
  • range

About

Enumerable for bash scripting

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages