本帖最后由 horizonhyg 于 2011-08-10 11:08 编辑 我现在一个函数中要返回一个值,作为一个变量再做后续处理,这个值很大,8位数,return不能得到么?我看完网上说return只能返回《=256的数,我这个返回值应该怎么得到?求大神解答下,谢谢 我试过了几种方法,都不行[code]funcname | read var echo $var[/code][code]funcname;var=$? echo $var[/code]以上两中都不可以
by horizonhyg - Shell - 2011-08-10 11:34:35 阅读(6218) 回复(10)
#/bin/bash ...... poolname=$(notInPool $BN) NP=$? ...... notInPool是一个函数。 请问,NP是函数的返回值还是上面命令执行结果?
#!/bin/bash sum_test() { a=(("$1"+"$2")) return a } b=sum_test "$1" "$2" echo $b ./sum_test.sh 10 20 输出: sum_test 为什么不是30呢?
请教一下shell 中函数返回值问题 现用shell写了一个脚本。check 远程机器port ,如正常 return 0,反之 ,return 1。另一个脚本会跟据返回值做相应处理。脚本部分内容如下: #!/bin/bash port=$1 check_port() { if [ -f $port ] then echo "ok" return 0 else echo "false" return 1 fi } check_port $port echo $? if [ $? -eq 0 ] then echo "ok" 执行其它脚本 else echo "fals" ...
函数为判断两个函数是否相等的函数,然后通过调用返回值在中断输出是否可以执行后面任务 #! /bin/sh export a=1; export b=2; export c=1; function compare(); { echo $1; echo $2; if [ $1 == $2 ] then echo “$1 is equal to $2”; return 1; else echo " $1 is not equal to $2"; return 0; fi; } compare $a $b echo $(compare) 这个结果输出是 ...
写了个脚本,如下:[code]#!/bin/bash os1_fun() { one=do1; two=do2; merge='$one $two' echo merge; } os2_fun() { one=do1; two=do2; merge='$one $two' echo merge; } get_merge=null case `uname` in 'Linux') get_merge=`os1_fun`;; 'SunOS') get_merge=`os2_fun`;; '*') get_merge=`os1_fun`;; esac echo $get_merge tmp=$get_merge grep $get_merg...
file a.c
#include
fun1() { return 0 } if fun1 then echo "run ok" fi 请问为什么上述脚本会打印出字符串? 按C语言的理解是函数返回0则if语句判断失败,不执行then后的语句,而我在Slackware 10.2系统下测试却打印出字符串. 是什么原因呢?谢谢.
fun1() { return 0 } if fun1 then echo "run ok" fi 请问为什么上述脚本会打印出字符串? 按C语言的理解是函数返回0则if语句判断失败,不执行then后的语句,而我在Slackware 10.2系统下测试却打印出字符串. 是什么原因呢?谢谢.