linux中创建自定义函数、加载自定义函数、调用自定义函数
1、创建自定义函数
格式:
function name {
command
}
[root@rhel7pc1 test]# ls test.sh [root@rhel7pc1 test]# cat test.sh ## shell中创建函数格式 #!/bin/bash function fun_test { echo "hello world!" }
2、加载、调用函数
[root@rhel7pc1 test]# ls test.sh [root@rhel7pc1 test]# cat test.sh #!/bin/bash function fun_test { echo "hello world!" } [root@rhel7pc1 test]# fun_test ## 函数未加载前 bash: fun_test: command not found... [root@rhel7pc1 test]# source test.sh ## 加载函数 [root@rhel7pc1 test]# fun_test ## 调用函数 hello world!
3、取消函数加载
[root@rhel7pc1 test]# fun_test ## 调用函数 hello world! [root@rhel7pc1 test]# unset fun_test ## 取消函数加载 [root@rhel7pc1 test]# fun_test ## 无法调用函数 bash: fun_test: command not found...
分类:
linux shell
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
2021-04-16 R语言中fig函数,图形布局的精细控制
2021-04-16 R语言中layout图形布局函数
2021-04-16 R语言中text函数
2021-04-16 R语言中使用locator(1)函数获取图形的位置坐标
2021-04-16 R语言中给图形添加图例
2021-04-16 R语言绘图abline函数 给图形增加参考线
2021-04-16 R语言绘图添加次要刻度线