Bash script while loop case statement example
How to create "Menu Lists" use Bash script while loop case statement. I'm use while loop with case statement create "Menu Lists". Bash script for fun!
The display color for echo command
Red color
My full bash script "bash script while loop case statement" example
I hope will this helpful for you
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
[huupv@huupv ~]$ ./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
Thank you for reading!
ReplyDeleteWow,great post.
ReplyDelete
ReplyDeleteHey 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