06shell函数_笔记
时间:2007-12-15 来源:bluexjj
06shell函数
*定义函数
*函数调用
*参数传递
*函数文件
*载入和删除函数
*函数换回状态
*函数定义
*shell容许将一组命令集或语句形成一个可用块,这些块称为shell函数
*定义函数的格式为:
-函数名( )
{
命令1
...........
} -function 函数名()
{
.......
} *函数可以放在同一个文件中作为一段代码,也可以放在只包含函数的单独文件中.
example_01:
#!/bin/bash
#hellofun function hello()
{
echo "Hello, today is `date`"
return 1
}
example_02:
#!/bin/bash
#hellofun
function hello()
{
echo "Hello, today is `date`"
return 1
}
echo "now going to the unction hello"
hello
echo "back from the function "
example_03:
#!/bin/bash
#hellofun function hello()
{
echo "Hello, $1 today is `date`"
}
echo "now going to the function hello"
hello chinaunix
echo "back from the function "
example_04:
#!/bin/bash
#func1
#Source function
. hellofun
echo "now going to the unction hello"
hello
echo "back from the function "
#!/bin/bash
#hellofun
function hello ()
{
echo "hello ,today is `date`"
return 1
} 检查载入函数和删除函数
*察看载入函数
set
*删除函数
unset
函数返回状态值 example_05:
#!/bin/bash
#hellofunctions
function hello ()
{
echo "Hello ,today is `date`"
return 0
}
#!/bin/bash
#func
. hellofunctions
echo "now going to the unctioin hello"
hello
echo $?
echo "back from the function "
*函数调用
*参数传递
*函数文件
*载入和删除函数
*函数换回状态
*函数定义
*shell容许将一组命令集或语句形成一个可用块,这些块称为shell函数
*定义函数的格式为:
-函数名( )
{
命令1
...........
} -function 函数名()
{
.......
} *函数可以放在同一个文件中作为一段代码,也可以放在只包含函数的单独文件中.
example_01:
#!/bin/bash
#hellofun function hello()
{
echo "Hello, today is `date`"
return 1
}
example_02:
#!/bin/bash
#hellofun
function hello()
{
echo "Hello, today is `date`"
return 1
}
echo "now going to the unction hello"
hello
echo "back from the function "
example_03:
#!/bin/bash
#hellofun function hello()
{
echo "Hello, $1 today is `date`"
}
echo "now going to the function hello"
hello chinaunix
echo "back from the function "
example_04:
#!/bin/bash
#func1
#Source function
. hellofun
echo "now going to the unction hello"
hello
echo "back from the function "
#!/bin/bash
#hellofun
function hello ()
{
echo "hello ,today is `date`"
return 1
} 检查载入函数和删除函数
*察看载入函数
set
*删除函数
unset
函数返回状态值 example_05:
#!/bin/bash
#hellofunctions
function hello ()
{
echo "Hello ,today is `date`"
return 0
}
#!/bin/bash
#func
. hellofunctions
echo "now going to the unctioin hello"
hello
echo $?
echo "back from the function "
相关阅读 更多 +