Skip to content
/ bash Public

A collection of handy functions for the shell script writing.

License

Notifications You must be signed in to change notification settings

Aludirk/bash

Repository files navigation

General library for Bash shell script (0.9.0)

A collection of handy functions for the shell script writing, it aims for Bash 3+.

Prerequisite

Some features are based on Perl5 to implement (use for PCRE).

Modules

All modules are tested in macOS and linux.

Module File Description
Command command.sh Command/Function utility.
Dictionary dictionary.sh Bash dictionary.
Environment File env.sh Environment file reader.
Message message.sh Show color message in shell.
Network network.sh Network utility.
String string.sh String manipulation.

Configuration

The following environment variables can be used to configure the behaviour of the library.

Debug mode

Set environment variable LIB_BASH_DEBUG to true to show error message in stderr when function get error.

Error message colors

Set environment variable LIB_BASH_ERROR_FG and LIB_BASH_ERROR_BG to change the foreground and background color respectively of error message, default is white and red, see ANSI escape code#Colors.

Information message color

Set environment variable LIB_BASH_INFO_COLOR to change the color of infomration message, default is green, see ANSI escape code#Colors.

Question message color

Set environment variable LIB_BASH_QUESTION_COLOR to change the color of question message, default is cyan, see ANSI escape code#Colors.

Error codes

All functions may return the following error codes.

Code Error
65 Invalid parameters.
66 Invalid options.
67 No outputs.
68 File does not exist.
69 Internal error.
70 Invalid regular expression.
71 Command not found.

Version History

0.9.0

  • local_ip for getting the IPv4 IP from command ifconfig
  • Dictionary for Bash 3.x and up.

0.7.0

  • select_option to let user to choose option from given array.

0.6.0

  • match_string for testing string that matches give regular expression.
  • regex_string for finding the matched pattern and capture groups.
  • replace_string for replacing string with regular expression.
  • Fix wrong output for newline character.
  • Fix wrong output for trailing newline.
  • Fix wrong output for empty string input.
  • Fix wrong output for UTF-8.

0.5.2

  • implode_string for imploding array to string and explode_string for exploding string to array.
  • load_env_file to read environment variables file.
  • Add escape_string.
  • Message module for printing colour string.
  • Fix skipping the unexpected options for get_option.
  • Fix get_option cannot handle special characters ‘“$’.
  • Fix cannot print colour string.

0.1.0

  • Add get_option to simulate the built-in function getopt.

About

A collection of handy functions for the shell script writing.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages