8th Shell Programming Character Menu Management
I. Shell function definition
Function menu () {
Echo ' This is a func!! ';
}
Two. Shell functions use
Menu
Three. How to use the Cat command Heredoc
Cat << EOF
Aaaaaaaaaaaaaaaa
Aaaaaaaaaaaaaaaa
Aaaaaaaaaaaaaaaa
Aaaaaaaaaaaaaaaa
Aaaaaaaaaaaaaaaa
Eof
Four. Color control of fonts under character interface
Echo-e "\033[30;47m Test \033[0m"
Five. How the shell contains files
VI func.sh
. menu.sh
Menu #执行menu The menu function in the. sh
Six. While how to write a dead loop
While True
Do
#执行代码
Done
Character Menu creation:
1. User add
2. User Delete
3. Change the password
4. View hard disk space usage
5. View memory space usage
6. Exit the Menu
#!/bin/bash
#index. Sh
. menu.sh
Clear
Menu
While True
Do
Read-p "Please input a option:" option
Case $option in
1)
Read-p "Add a User:" Name
Useradd $name &>/dev/null
If [$?-eq 0];then
str= "User ${name} is created successfully!!!"
Echo-e "\033[30;47m$str\033[0m"
Else
str= "User ${name} is created failly!!!"
Echo-e "\033[31;47m$str\033[0m"
Fi
;;
2)
Read-p "Input the User:" Name
Read-p "Set pass for the user:" Pass
echo $pass | passwd--stdin $name &>/dev/null
If [$?-eq 0];then
Str= "${name} ' s password is set successfully!!!"
Echo-e "\033[30;47m$str\033[0m"
Else
Str= "${name} ' s password is set failly!!!"
Echo-e "\033[31;47m$str\033[0m"
Fi
;;
3)
Read-p "Delete a User:" Name
Userdel-r $name &>/dev/null
If [$?-eq 0];then
str= "User ${name} is deleted successfully!!!"
Echo-e "\033[30;47m$str\033[0m"
Else
str= "User ${name} is deleted failly!!!"
Echo-e "\033[31;47m$str\033[0m"
Fi
;;
4)
Str= ' Free-m '
Echo-e "\033[30;47m$str\033[0m"
;;
5)
Str= ' df-th '
Echo-e "\033[30;47m$str\033[0m"
;;
6)
Echo-e "\033[30;47mquit successfully!! \033[0m "
Break
;;
7)
Clear
Menu
;;
Esac
Done
#!/bin/bash
#menu. Sh
Function menu () {
title= "My Menu"
Url= "Www.lampym.com"
Time= ' Date +%y-%m-%d '
Cat << EOF
#######################################
' Echo-e ' \033[32;40m$title\033[0m "'
#######################################
*) Add a user
* *) Set password for user
Delete a user
Print disk space
() Print Mem space
*6) quit
*7) return main Menu
#######################################
$url $time
#######################################
Eof
}
Shell writing character Menu Management-8