The display color for echo command
Red color
RED='\033[0;31m'Blue color
BLUE='\033[0;34m'No color
NC='\033[0m'Read from standard input and write to standard output and files
tee -a /tmp/log__$DATETo run bash script
[[email protected] ~]$ ./menu_listThe display as below:
Menu Lists
1) My blog
2) Your name
3) How old are you?
4) Your Hobbies
5) Quit
>>
My full bash script "bash script while loop case statement" example
#!/bin/bash
# author: HuuPV
RED='\033[0;31m'
BLUE='\033[0;34m'
NC='\033[0m' #No color
DATE=$(date +%Y%m%d)
while true
do
echo ""
echo -e "$BLUE Menu Lists $NC"
echo -e ""
echo -e "$BLUE 1) My blog $NC"
echo -e "$BLUE 2) Your name $NC"
echo -e "$BLUE 3) How old are you? $NC"
echo -e "$BLUE 4) Your hobit $NC"
echo -e "$BLUE 5) Quit $NC"
echo -n ">> "
read case
case "$case" in
1)
read -p "Are you sure? [y/N] " response
if [[ "$response" =~ ^([yY][eE][sS]|[yY])+$ ]]
then
echo "www.huuphan.com! ^_^"
else
echo "Nothing!"
fi
;;
2)
read -p "Are you sure? [y/N] " response
if [[ "$response" =~ ^([yY][eE][sS]|[yY])+$ ]]
then
read -p "Your Name :" NAME
echo $NAME
else
echo "Nothing!"
fi
;;
3)
read -p "Are you sure? [y/N] " response
if [[ "$response" =~ ^([yY][eE][sS]|[yY])+$ ]]
then
read -p "How old are you:" OLDD
echo $OLDD
else
echo "Nothing!"
fi
;;
4)
read -p "Are you sure? [y/N] " response
if [[ "$response" =~ ^([yY][eE][sS]|[yY])+$ ]]
then
read -p "Your Hobbies:" HOB
echo $HOB
else
echo "Nothing!"
fi
;;
5) break;;
esac
done | tee -a /tmp/log_$DATE
echo -e "$RED Exit ^_^ $NC"
I hope will this helpful for you
Thanks for reading Bash script while loop case statement example My blog Zimbra Mail Server,linux,bash script,centos,linux command I hope this is useful.
4 Comments
Thank you for reading!
RelayHi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here. Kindly keep blogging. If anyone wants to become a Java developer learn from Java Training in Chennai. or learn thru Java Online Training India . Nowadays Java has tons of job opportunities on various vertical industry.
RelayWow,great post.
RelayHey There. I found your blog using msn. This is a very well written article. I will make sure to bookmark it and return to read more of your useful info. Thanks for the post. I'll certainly comeback. aol.com mail login