Created by Paul-Emmanuel Raoul / skyper@skyplabs.net / @SkypLabs
One-file Bash library
Free and open-source software (New BSD)
Forked from Louwrentius' work
Display well-presented messages
Log easily what your scripts do
Handle commands' output
Test network information (IPv4, FQDN...)
Use timers
Manipulate arrays intuitively
...
No libraries shipped with Bash
Simple tasks can be difficult to achieve with shell scripts somethimes
Use Bash 4+ and include BSFL at the beginning of your scripts
#!/usr/bin/env bash
declare -r DIR=$(cd "$(dirname "$0")" && pwd)
source $DIR/../lib/bsfl.sh
#!/usr/bin/env bash
source /opt/bsfl/bsfl.sh
Take a look at the examples directory
Display a simple message:
msg "Hello, World!"
With a specific colour:
msg "Hello, World!" "$RED"
With a status:
msg_alert "Hello, World!"
Many status already exist:
Log a simple message:
log "Hello, World!"
With a status:
log_critical "Hello, World!"
Just like for messages, many status are available:
Functions' output is logged only if the logging feature is enabled:
LOG_ENABLED=y
By default, log messages are written into a file in the current directory:
declare LOG_FILE="$0.log"
For exemple, for test.sh, the log file will be test.sh.log
You can override this behaviour:
LOG_FILE="filename.log"
If the logging feature is enabled, standard messages are also logged:
Execute a simple command:
cmd "ls -al"
cmd "pnig 8.8.8.8"
The function cmd handles the output depending on the command's exit status:
By default, the command's output is not displayed. To override this behaviour:
DEBUG=y
Test an IPv4:
cmd "is_ipv4 8.8.8.8"
Test an IPv4 subnet:
cmd "is_ipv4_subnet 192.168.1.0/24"
Test an FQDN address:
cmd "is_fqdn www.example.net"
Convert an IPv4 mask into CIDR and vice versa:
mask2cidr 255.255.255.0
cidr2mask 24
Many other features!
Take a look at the online Doxygen documentation:
Without BSFL:
echo $ntp | grep -Eq $regex_ipv4
if [ "$?" -ne 0 ]; then
echo $ntp | grep -Eq $regex_fqdn
if [ "$?" -ne 0 ]; then
echo "NTP address $ntp is not an IPv4 nor an FQDN" >> $logfile
exit 1
fi
fi
With BSFL:
is_ipv4 $ntp || is_fqdn $ntp
die_if_false $? "NTP address $ntp is not an IPv4 nor an FQDN."
Get involved!
Contributions are welcomed