[Bash] Understand and Use Functions in Bash
n this lesson,we‘ll go over how bash functions work. Bash functions work like mini bash scripts--you can pass parameters and invoke them just like a bash command. You can also define local variables within a bash function using the?
?
Define and call a function:
//script.sh greet() {
echo "hello world" } greet // call a function
?
? Pass parameters to the function: greet() { echo "$1 world" } greet "hello" $1: means the first param passed in to the function. ? Get the return value: greet() { return "$1 world" } greet "Hello" greeting = $(greet "Hello") $(): get the return as a result. ? Global vs local variables: global = 123 test() { echo "global = $global" local local_var = "i am a local" echo "local_var = $local_var" } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
- angular2 – systemjs.config.js在角度2包装结构中做什么?
- Bootstrap下拉菜单更改为悬停(hover)触发的方法
- twitter-bootstrap – 如何在Bootstrap – Carousel中将图像
- 短信WebService接口文档
- 如何在angular2 webpack中使用jquery?获得$not defined
- 从Play2 / Scala内存中的MultipartFormData中提取文件
- shell脚本初入门必读
- bash scripting:如果参数等于此字符串,请定义一个类似此字
- 【WebService】——CXF整合Spring
- 手把手教你SOAP访问webservice并DOM解析返回的XML数据