Skip to content

a shel file to facilitate a bash based logger lib

Notifications You must be signed in to change notification settings

talknopf/bash_toolkit

Repository files navigation

BASH toolkit v1.0

for those time you simply have to work with bash but you want you script to be top notch! this tool is basically a collection of smaller tools i gathered over time some wrote by me, some i just improved or adapted.

How to use the logger:

This wrapper will allow you to display colorful logging along with actual logfile to be generated by your scripts tha basics of using the logs are:

info "info message text"

warn "warn message text"

error "error message text"

exit_on_error "error message text" "<exit code>"

Command line parsing and validation:

up until now you had to either used numbered arguments ./script.sh $1 $2 $3 ... or somtimes ./script.sh $@

To parse the arguments:

all you need to do is call upon 'parse args' function along with input array and parsing will be done. ``` parse_args $@ ```

so to give a more practical example:

./script.sh -arg1 "foo" -arg2 "bar"

and within the script you will have the following variables:

ARG1='foo'
ARG2='bar'

To validate the arguments and variables:

when before you needed to validate in such manner: `[[ $VAR1 ]] || exit 1`

now you can validate by using the validate_args "VAR1" "VAR2" if the variable is not defined you will recieve an elborate error on it being missing

Installation

just clone the repo to the location of your choosing

Testing the installation

running the built-in test script will show you and example of the functions mentioned above. this script will exit with an error, it should be doing that.

./bash_tools_tester.sh -t foo -r bar

How to use?

source /path/to/folder/bash_toolkit.sh from this point on you can simply call upon the functions

Please let me know should you have any issues and/or requests: [email protected]

About

a shel file to facilitate a bash based logger lib

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages