On Github SkypLabs / bsfl-slideshow
Created by Paul-Emmanuel Raoul / skyper@skyplabs.net / @SkypLabs
One-file Bash library
Free Open Source Software (New BSD)
Forked from Louwrentius' work
Display well-presented messages
Log easily what your script does
Handle commands' output
Test network informations (IPv4, FQDN, ...)
Use timers
Manipulate arrays intuitively
...
No libraries embedded with Bash
Simple tasks can be hard to do with shell scripts
Use version 4 of Bash and include BSFL at the beginning of your script
#!/bin/bash declare -r DIR=$(cd "$(dirname "$0")" && pwd) source $DIR/../lib/bsfl.sh
#!/bin/bash source /opt/bsfl/bsfl.sh
Take a look at the "examples" directory
Display a simple message :
msg "This is a classic displayed message using 'msg' function."
With a specific color :
msg "This is a red displayed message using 'msg' function with color parameter." "$RED"
With a status :
msg_alert "This is a displayed message with its status using 'msg_alert' function."
Many status already exist :
Log a simple message :
log "This is a simple message to log."
With a status :
log_critical "This is a logged message using 'log_critical' function."
Just like for messages, many status are available :
By default, the messages are logged in 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 overwrite this behavior :
LOG_FILE="filename.log"
You can even log standard messages :
LOG_ENABLED=y msg "Thus, this message is logged in a file."
Execute a simple command :
cmd "ls -al" cmd "pnig 8.8.8.8"
The cmd function handles the output depending on the command's status :
By default, the command's result is not displayed. To overwrite this behavior :
DEBUG=y cmd "ls -al"
Test an IPv4 :
cmd "is_ipv4 8.8.8.8"
Test an IPv4 subnet :
cmd "is_ipv4_subnet 192.168.1.0/24"
Test a 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 or FQDN" >> $logfile exit 1 fi fi
With BSFL :
is_ipv4 $ntp || is_fqdn $ntp die_if_false $? "NTP address $ntp is not an IPv4 or a FQDN."
Get involved !
Contributions are welcomed