[SOLVED] What does '!' exclamation mark mean in the bash conditional statement?
by pinqvin from LinuxQuestions.org on (#59ENP)
Hi there. New to bash scripting... I know that '!' exclamation mark is widely used in string operations and as a negation in other programming languages. But what does it mean in this function? Can you please explain what the conditional is supposed to do exactly?
Code:#!/bin/bash
# Fancy colorful echo messages
function echo_message(){
local color=$1;
local message=$2;
if ! [[ $color =~ '^[0-9]$' ]]; then
case $(echo -e $color | tr '[:upper:]' '[:lower:]') in
# black
header) color=0 ;;
# red
error) color=1 ;;
# green
success) color=2 ;;
# yellow
welcome) color=3 ;;
# blue
title) color=4 ;;
# purple
info) color=5 ;;
# cyan
question) color=6 ;;
# orange
warning) color=202 ;;
# white
*) color=7 ;;
esac
fi
tput bold;
tput setaf $color;
echo '-- '$message;
tput sgr0;
}Thank you!
Rustam


Code:#!/bin/bash
# Fancy colorful echo messages
function echo_message(){
local color=$1;
local message=$2;
if ! [[ $color =~ '^[0-9]$' ]]; then
case $(echo -e $color | tr '[:upper:]' '[:lower:]') in
# black
header) color=0 ;;
# red
error) color=1 ;;
# green
success) color=2 ;;
# yellow
welcome) color=3 ;;
# blue
title) color=4 ;;
# purple
info) color=5 ;;
# cyan
question) color=6 ;;
# orange
warning) color=202 ;;
# white
*) color=7 ;;
esac
fi
tput bold;
tput setaf $color;
echo '-- '$message;
tput sgr0;
}Thank you!
Rustam