【Purpose】
Shell print function base on err info wrn ext output level
【Eevironment】
Ubuntu 16.04 bash env
【Procdeure】
Source code:
#!/bin/bash
DEST=/tmpmkdir -p /tmp/debugdisplay_alert()#--------------------------------------------------------------------------------------------------------------------------------# Let's have unique way of displaying alerts#--------------------------------------------------------------------------------------------------------------------------------{ # log function parameters to install.log #[[ -n $DEST ]] && echo "Displaying message: $@" >> $DEST/debug/output.loglocal tmp=""
[[ -n $2 ]] && tmp="[\e[0;33m $2 \x1B[0m]"case $3 in
err) echo -e "[\e[0;31m error \x1B[0m] $1 $tmp" ;;wrn)
echo -e "[\e[0;35m warn \x1B[0m] $1 $tmp" ;;ext)
echo -e "[\e[0;32m o.k. \x1B[0m] \e[1;32m$1\x1B[0m $tmp" ;;info)
echo -e "[\e[0;32m o.k. \x1B[0m] $1 $tmp" ;;*)
echo -e "[\e[0;32m .... \x1B[0m] $1 $tmp" ;; esac}display_alert "List of local repos" "local" "err"display_alert "List of local repos" "local" "wrn"display_alert "List of local repos" "local" "ext"display_alert "List of local repos" "local" "info"display_alert "List of local repos" "local" "other"
Test method: