Tag: Please user null
Syntax format
Function Name (){
Function body
}
Function Name
--------------------------
Function body can contain command loop judgment
Example: Determine whether a user exists. The output user ID and shell exist.
#! /Bin/bash
Username (){
Read-P "Please Username:" username
If Id $ username &>/dev/NULL; then
Name = $ (grep "^ $ username"/etc/passwd | cut-D:-F3, 7)
Id = $ (echo $ name | cut-D:-F1)
Shell = $ (echo $ name | cut-D:-F2)
Echo-e "username: $ USERNAME \ NID: $ ID \ nshell: $ shell"
Else
Echo "$ username not"
Fi
}
Username
------------------------------------
Function return value
1. execution results, usually Output Using echo or print
2. Status Return Value
The variables in the function will affect the value of the main variable.
Lock variable name = value converts a variable to a local variable
This article from the "hanging sword" blog, please be sure to keep this source http://sublime.blog.51cto.com/8856101/1545062
Shell script ----- Function