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