#!/bin/bash -
function mytest()
{
echo "arg1 = $1"
if [ $1 = "1" ] ;then
return 1
else
return 0
fi
}
echo
echo "mytest 1"
mytest 1
echo $? # print return result
echo
echo "mytest 0"
mytest 0
echo $? # print return result
echo
echo "mytest 2"
mytest 2
echo $? # print return result
echo
echo "mytest 1 = "`mytest 1`
if mytest 1 ; then
echo "mytest 1"
fi
echo
echo "mytest 0 = "`mytest 0`
if mytest 0 ; then
echo "mytest 0"
fi
echo
echo "if fasle" # if 0 is error
if false; then
echo "mytest 0"
fi
echo
mytest 1
res=`echo $?` # get return result
if [ $res = "1" ]; then
echo "mytest 1"
fi
echo
mytest 0
res=`echo $?` # get return result
if [ $res = "0" ]; then
echo "mytest 0"
fi
echo
echo "end"
#!/bin/bash -
g_var=
function mytest2()
{
echo "mytest2"
echo "args $1"
g_var=$1
return 0
}
mytest2 1
echo "return $?"
echo
echo "g_var=$g_var"
#!/bin/bash -
function mytest3()
{
grep "123" test.txt | awk -F: '{print $2}' | while read line ;do
echo "$line"
if [ $line = "yxb" ]; then
return 0 # return to pipe only
fi
done
echo "mytest3 here "
return 1 # return to main process
}
g_var=
function mytest4()
{
grep "123" test.txt | awk -F: '{print $2}' | while read line ;do
echo "$line"
if [ $line = "yxb" ]; then
g_var=0
echo "g_var=0"
return 0 # return to pipe only
fi
done
echo "mytest4 here "
return 1
}
mytest3
echo $?
echo
mytest4
echo $?
echo
echo "g_var=$g_var"
#!/bin/bash
##############################################
# Author : IT-Homer
# Date : 2012-09-06
# Blog : http://blog.csdn.net/sunboy_2050
##############################################
function mytest5()
{
grep "123" test.txt | awk -F: '{print $2}' | while read line; do
if [ $line = "yxb" ]; then
echo "0" # value returned first by this function
return 0
fi
done
return 1
}
echo '$? = '"$?"
result=$(mytest5)
echo "result = $result"
echo
if [ -z $result ] # string is null
then
echo "no yxb. result is empyt"
else
echo "have yxb, result is $result"
fi
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有