shell函数
1.定义函数 4.函数文件
2.函数调用 5.载入和删除函数
3.参数传递 6.函数返回状态
1.定义函数
语法:
[ function ] funname [()]
{
action;
[return int;]
}
说明:
1、可以带function fun() 定义,也可以直接fun() 定义,不带任何参数。
2、参数返回,可以显示加:return 返回,如果不加,将以最后一条命令运行结果,作为返回值。 return后跟数值n(0-255
#!/bin/bash
#hello fun
function hello() {
echo "hello fun,today is `date`"
return 1
}
2.函数调用
#!/bin/bash
#hello fun
function hello() {
echo "hello fun,today is `date`"
return 1
}
echo "exec funtion"
hello
echo "finish"
3.参数传递
#!/bin/bash
#hello fun
function hello() {
echo "hello $1,today is `date`"
return 1
}
echo "exec funtion"
hello world
echo "finish"
4.函数文件
#!/bin/bash
#hello fun
#source function
. hellofun
echo "now going to the function hello"
hello
echo "back from function hello"
function hello() {
echo "hello,today is `date`"
return 1
}
5.函数的载入查看与删除函数
#!/bin/bash
#hello fun
#source function
. hellofun
set #[color=darkred]查看函数是否载入[/color]
#unset 删除函数
echo "now going to the function hello"
hello
echo "back from function hello"
function hello() {
echo "hello,today is `date`"
return 1
}
6.函数返回状态
#!/bin/bash
#hello fun
#source function
. hellofun
echo "now going to the function hello"
hello
echo $?
echo "back from function hello"
function hello() {
echo "hello,today is `date`"
return 1
}
注意:一般返回 0 为正确 1 为错误。
shell函数没有返回值,返回的都是状态值
分享到:
相关推荐
linux shell学习资料:Linux Shell从入门到精通、Linux Shell编程艺术、Linux Shell脚本攻略
Linux_shell脚本全面学习 Linux_shell脚本全面学习
资源名称:Linux Shell脚本学习基础视频资源目录:【】11a00d99b60c4e2eba3440b8aa3a6bdd【】linux_shell脚本编程_01认识shell,如何编写shell脚本和执行【】linux_shell脚本编程_02vivim简单的常用操作【】linux_...
Linux-shell脚本全面学习.pdf
shell学习基本命令,可以帮助初学者快速掌握较全面的shell脚本知识
Linux shell是学习Linux必须掌握的脚本之一,该文档为本人学习Shell脚本时总结的一些基础知识,包括Shell的语法、简单示例和总结,欢迎下载学习。
linux shell 视频教学 轻松学习shell
linux shell 应用.chm,学习linux shell资料
linux shell 编程电子书,学习linux shell很不错的资料,高清的
Linux shell脚本全面学习 1. Linux 脚本编写基础 1.1 语法基本介绍 1.1.1 开头 程序必须以下面的行开始(必须方在文件的第一行): #!/bin/sh 符号#!用来告诉系统它后面的参数是用来执行该文件的程序。在这个例子中...
分别有以下这些内容的资料 Linux与unix shell编程指南 Bash参考手册 Expect中文教程 Expect简介和应用 Expect命令基本语法 高级Bash脚本编程指南 高级Shell脚本编程 Shell命令合集
本书旨在通过理清Linux Shell编程的脉络,从基本概念着手,以丰富、实用的范例作为辅助,使读者能够深入浅出的学习LinuxShell编程。 本书的每一章节都配有综合案例,这些综合案例不仅可以使读者复习前面所学的...
非常全面的介绍linux下shell脚本的教程,入门级教程,如果你是菜鸟,本文档非常适合你。
Linux shell 脚本攻略,学习linux新手入门的较好教材,第二版,现已出版第三版
Linux 下关于shell命令的基本介绍 gwak iconv函数 sz和rz命令 数组的基本操作 ls命令
Linux shell脚本全面学习
学习linux shell的不错选择 带书签
linuxShell脚本编写实验7报告.pdf
这是学习Shell的简单例子这是学习Shell的简单例子这是学习Shell的简单例子
很不错的Linux Shell的详细学习文档,大家来看看吧