环境:ubuntu10.10 + bash
函数定义以及传参
#! /bin/sh test() { echo $1 #打印第一个参数 } a='hello,world' test $a #参数必须是定义好的变量
传递两个参数
#! /bin/sh test() { echo $1 #打印第一个参数 echo $2 return 127 #只能返回整数 } test 'hello,world!' 'lishujun' #传递两个参数 echo $? #取得函数返回值,调用完毕立即取值
取得返回值
#! /bin/sh test() { echo $1 #打印第一个参数 return 127 #只能返回整数 } a='hello,world' test $a #必须这么传值 echo $? #取得函数返回值,调用完毕立即取值