Shell function function

Source: Internet
Author: User

1. Functions
Shell functions, which are used to customize a segment of a program. To simplify the code. Grammar:
Funtion fname () {    //do something}

The shell is top-down, executed from the left and right. So the definition of the function needs to precede the call. For example:
#!/bin/bash# author:yonggangfunction print_it () {    echo-n "Your choice is:"}case $ in    "one")        print_it; EC Ho $;;    " ") Print_it; echo $;;;    " Three ")        Print_it, Echo    $;;; *)        echo "Usage (One|two|three)"        ;; Esac
Perform:
[[Email protected] sh]$ sh func.sh twoyour choice is:two[[email protected] sh]$ sh func.sh oneyour Choice Is:one[[emai L Protected] sh]$
2. function parameter passing
function also has built-in variables, similar to shell script. $# parameter number of the first parameter, the second argument ... [email protected] All parameters see the following example:
#!/bin/bash# author:yonggangfunction Print_param () {    echo "paramter number:" $#    echo "First paramter:" $1
   
    echo "Second paramter:" $    echo "all paramter:" [email Protected]}print_param One and three
   
Run:
[[Email protected] sh]$ sh func.sh paramter number:  3first paramter:  onesecond paramter:  twoall paramter:  

Address: http://blog.csdn.net/yonggang7/article/details/40679111

Shell function 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.