Use of function functions for shell scripts

Source: Internet
Author: User
Use of function functions for shell scripts
? The basic things in front of the introduction, the following we introduce the function how to use.
? Note: The function needs to be declared before it can be used.
? The declared keyword can be used with the function keyword, or it can be ignored
? Let's look at three simple output color features:

#!/bin/bash
function rmsg () {echo-e "\033[31;49m$\033[0m";} #输出红色
Gmsg () {echo-e "\033[32;49m$
\033[0m";} #输出绿色
Bmsg () {ECHO-E "\033[34;49m$*\033[0m";} #输出蓝色

RMSG Red
Gmsg Green
BMSG Blue

? The first output red function, using the function keyword, gmsg and bmsg are not used
? function calls directly with the name of the function, followed by parameters, parameters are separated by a space.
? The $* inside the function represents the receipt of all parameters
? If you use $ $, the function will receive the first parameter

Use of function functions for shell scripts

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.