shell 之函数
来源:互联网 发布:java表格 插件 编辑:程序博客网 时间:2024/06/05 14:20
shell 函数的定义function_name(){ statements}下面实现一个例子foo(){ echo "Function foo is executing"}echo "script starting"fooecho "script ended"exit 0你在调用一个函数之前必须先对他定义利用local 去声明局部变量 全局变量和局部变量名字相同,局部变量覆盖全局变量下面一个例子sample_text = "global variable"foo(){ local sample_text = "local variable" echo "function foo is executing" echo $sample_text}echo "start"echo $sample_text foo echo "end"echo $sample_textexit 0函数中返回一个值yes_or_no(){ echo "is your name $* ?" while true do echo -n "enter yes or no" read x case "$x" in y|yes ) return 0;; n|no ) return 1;; *) echo "answer yes or no" esacdone}echo "original parameters are $*"if yes_or_no "$1"then echo "hi $1,nice name"else echo "never mind"fiexit 0为了看懂上面的程序先复习一下 命令行参数特殊变量列表变量 含义$0 当前脚本的文件名$n传递给脚本或函数的参数。n 是一个数字,表示第几个参数。例如,第一个参数是$1,第二个参数是$2。$# 传递给脚本或函数的参数个数。$* 传递给脚本或函数的所有参数。$@传递给脚本或函数的所有参数。被双引号(" ")包含时,与 $* 稍有不同,下面将会讲到。$? 上个命令的退出状态,或函数的返回值。$$ 当前Shell进程ID。对于 Shell 脚本,就是这些脚本所在的进程ID。
阅读全文
0 0
- Shell编程之 函数
- shell 编程之函数
- linux shell 之函数
- shell之函数
- shell脚本之函数
- shell 之函数
- shell脚本之函数
- Shell之函数-yellowcong
- Linux Shell 之 Shell中的函数调用
- Linux Shell 之 Shell中的函数调用
- linux学习之shell脚本 ------- shell函数
- Linux Shell 之 Shell中的函数调用
- Linux Shell 之 Shell中的函数调用
- Linux Shell 之 Shell中的函数调用
- Linux Shell 之 Shell中的函数调用
- Linux Shell 之 Shell中的函数调用
- Linux Shell 之 Shell中的函数调用
- Shell编程之函数笔记
- EL表达式
- a letter and a number
- html div中怎么引入另一个html文件
- 没有与参数列表匹配的 重载函数 AfxMessageBox()
- 设计模式之状态模式(State)
- shell 之函数
- Jokerlibrary——Android应用开发框架
- 数字与字符串之间的转换
- c++ builder 中的 XMLDocument 类详解(4)
- Android——dialog style属性
- js之自定义事件
- 实现新年倒计时
- 170614 Windows10+Anaconda2/3+tensorflow-1.2.0rc2(cpu & gpu) 安装
- 【小白自总结】计量地理学 各章节导图(更新中)