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