#!/bin/bash
#hello-fun
function hello()
{
echo "hello,today is `date`"
return 1
}
#!/bin/bash
#func
function hello()
{
echo "hello,today is `date`"
}
echo "now going to the function helo()"
hello #直接写函数文件名进行函数调用
echo "back from the hell()"
#!/bin/bash
#func
function hello()
{
echo "hello $1"
}
echo "now going to the function helo()"
hello argument-1 # argument-1 是 $1
echo "back from the hello()"
#!/bin/bash
#func
#source function
. hellofun # hellofun 文件里有需要调用的函数
echo "now going to the function hello"
hello
echo "back from the function"
#!/bin/bash
#hellofun
functon hello()
{
echohello, today is `date`
"
return 1
}
#!/bin/bash
#hellofunctions
function hello()
{
echo "hello,today is `date`"
return 0
}
#!/bin/bash
#func
. hellofunctions # include 函数文件
echo "now going to the function hello"
hello
echo $? # 特殊变量 $? 得到返回值
echo "back from the function"
#!/bin/sh
function myfunc() {
echo "return a value"
return 2
}
myfunc
ret=$?
echo $ret
[beyes@beyes command]$ sh tmp.sh
return a value
2
欢迎光临 曲径通幽论坛 (http://www.groad.net/bbs/) | Powered by Discuz! X3.2 |