learning shell display alert function(5)

 

Purpose

       Shell print function base on err info wrn ext output level

 

Eevironment

       Ubuntu 16.04 bash env

 

Procdeure

  Source code:

#!/bin/bash
DEST=/tmp
mkdir -p /tmp/debug
display_alert()
#--------------------------------------------------------------------------------------------------------------------------------
# Let's have unique way of displaying alerts
#--------------------------------------------------------------------------------------------------------------------------------
{
# log function parameters to install.log
#[[ -n $DEST ]] && echo "Displaying message: $@" >> $DEST/debug/output.log

local 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:

posted @ 2019-02-18 11:15  嵌入式实操  阅读(242)  评论(0编辑  收藏  举报