定义函数
function fname()
{
statements;
}
或者
fname()
{
statements;
}
传递参数给函数:
fname arg1 arg2;
ex:
函数参数定义:
fname()
{
echo $1, $2;
echo "$@";
echo "$*";
return 0;
}
检测命令是否成功执行
#!/bin/bash#filename:success_test.shcmd="ls"$cmdif [ $? -eq 0 ];then echo "$cmd executed successfully"else echo "$cmd terminated unsuccessfully"fi