Shell writing character Menu Management-8

Source: Internet
Author: User
Tags function definition

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.