0

45、shell编程-函数

 1 year ago
source link: https://blog.51cto.com/gavenlee/5766904
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

45、shell编程-函数

精选 原创

GavenLee 2022-10-18 15:49:41 博主文章分类:Linux系统 ©著作权

文章标签 函数调用 调用函数 函数 文章分类 Linux 系统/运维 阅读数197

函数function是由多个shell组成的语言块,实现代码重用和模块化编程,与shell类型,不同点为shell程序运行会单独开启进程,而函数不会开启进程,是在当前shell环境中运行,可影响当前shell的变量。

function_name (){
command
}
或者
function function_name (){
command
}
45、shell编程-函数_函数调用
45、shell编程-函数_函数_02
函数查看及删除
45、shell编程-函数_调用函数_03

declare -F 查看所有定义的函数

declare -f 函数名  查看特定函数

unset 函数名 删除函数

45、shell编程-函数_函数调用_04

直接使用函数名执行

45、shell编程-函数_函数_05

在脚本中执行

45、shell编程-函数_调用函数_06

作为函数文件被调用

在shell脚本或交互式shell中调用函数文件,格式如下:

. filename 或 source filename
45、shell编程-函数_调用函数_07
  • 收藏
  • 2评论
  • 分享
  • 举报

上一篇:循环脚本编写


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK