[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 local
keyword. Local variables follow similar scope rules present in most programming languages.
- //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 =
- test() {
- echo "global = $global"
- local local_var = "i am a local"
- echo "local_var = $local_var"
- }
[Bash] Understand and Use Functions in Bash的更多相关文章
- -bash: /etc/init.d/nginx: /bin/bash^M: bad interpreter: No such file or directory
-bash: /etc/init.d/nginx: /bin/bash^M:bad interpreter: No such file or directory 这个使为了弄nginx自启的,然后在官 ...
- Bash+R: howto pass parameters from bash script to R(转)
From original post @ http://analyticsblog.mecglobal.it/analytics-tools/bashr/ In the world of data a ...
- Understand JavaScript Callback Functions and Use Them
In JavaScript, functions are first-class objects; that is, functions are of the type Object and they ...
- #VScodd集成Git Bash 命令行 #怎么把Git Bash集成到VScode
配置 Step1. File-Preferences-Setting Step2. 搜索"terminal>integrated>shell A" Step3. 找到t ...
- win-sudo插件解决Git bash 执行脚本报错问题 bash: sudo: command not found
Windows git bash 默认没有sudo命令,可以添加win-sudo插件实现该功能 curl -s https://raw.githubusercontent.com/imachug/wi ...
- Linux下运行bash脚本显示“: /usr/bin/env: "bash\r": 没有那个文件或目录
用 ./ 运行bash脚本文件出现 报错信息 /usr/bin/env: "bash\r": 没有那个文件或目录 错误原因:这主要是因为bash后面多了\r这个字符的原因.在lin ...
- [Bash] View Files and Folders in Bash
Sometimes when working at the command line, it can be handy to view a file’s contents right in the t ...
- CVE: 2014-6271、CVE: 2014-7169 Bash Specially-crafted Environment Variables Code Injection Vulnerability Analysis
目录 . 漏洞的起因 . 漏洞原理分析 . 漏洞的影响范围 . 漏洞的利用场景 . 漏洞的POC.测试方法 . 漏洞的修复Patch情况 . 如何避免此类漏洞继续出现 1. 漏洞的起因 为了理解这个漏 ...
- Linux学习笔记(15)shell基础之Bash基本功能
1 shell概述 shell是一个命令解释器,为用户提供了一个向Linux内核发送请求以便运行程序的界面系统级程序.用户可以用shell启动.挂起.停止甚至是编写一些程序. shell是一个功能强大 ...
随机推荐
- 贪心 - [POI2006]ORK-Ploughing
[POI2006]ORK-Ploughing 描述 Byteasar 想耕种他那块矩形的田,他每次能耕种矩形的一边(上下左右都行),在他每次耕完后,剩下的田也一定是矩形,每块小区域边长为 1,耕地的长 ...
- 大数据学习——sparkRDD
https://www.cnblogs.com/qingyunzong/p/8899715.html 练习1:map.filter //通过并行化生成rdd val rdd1 = sc.paralle ...
- datatable 修改点击列头进行排序顺序
一般点击排序时,是先升序后降序 可以通过如下代码修改排序规则 jQuery(function ($) { $(".datatable").dataTable({ "pag ...
- 微信小程序开发 -- 手机振动
wx.vibrateLong(OBJECT) wx.vibrateLong(OBJECT) 方法使手机发生较长时间的振动(400ms) OBJECT参数说明: 参数名 类型 必填 说明 success ...
- 5中IO模型整理总结
1.5中IO模型: 阻塞I/O(blocking IO) 非阻塞I/O(noblocking IO) I/O复用 (IO multiplexing ) 信号驱动I/O (signal drive ...
- 以前刷过的数位dp
TOJ1688: Round Numbers Description The cows, as you know, have no fingers or thumbs and thus are una ...
- 数据表自动生成java代码
MyBatis生成代码需要用到mybatis-generator-core-1.3.2.jar.数据库连接驱动包和一个xml文件,xml文件一般命令为:generator.xml. Xml内容格式如下 ...
- 【Luogu】P4231三步必杀(差分,差分)
题目链接 郑重宣布我以后真的再也不会信样例了,三种写法都能过 另:谁评的蓝题难度qwq 蓝题有这么恐怖吗 两次差分,第一次差分,前缀和求出增量数组,第二次求出原数组顺便更新答案 看题解之后……第二次差 ...
- 【Luogu】P3317重建(高斯消元+矩阵树定理)
题目链接 因为这个专门跑去学了矩阵树定理和高斯消元qwq 不过不是很懂.所以这里只放题解 玫葵之蝶的题解 某未知dalao的矩阵树定理 代码 #include<cstdio> #inclu ...
- Java数据库连接JDBC用到哪种设计模式?
还没看桥接模式,占tag 桥接模式: 定义 :将抽象部分与它的实现部分分离,使它们都可以独立地变化. 意图 :将抽象与实现解耦. 桥接模式所涉及的角色 1. Abstraction :定义抽象接口, ...