Shell script ----- Function

Source: Internet
Author: User

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

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.