ChinaUnix.net
相关文章推荐:

shell脚本 函数返回值

file a.c #include int main() { int i; for(i=0; i<10; i++) { printf("%d\n",i); } return 15; } gcc -o a a.c 如何在shell脚本中接收a的返回值

by daniel_kohler - Shell - 2010-01-19 14:23:24 阅读(3775) 回复(4)

相关讨论

本帖最后由 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 阅读(5748) 回复(10)

#/bin/bash ...... poolname=$(notInPool $BN) NP=$? ...... notInPool是一个函数。 请问,NP是函数返回值还是上面命令执行结果?

by howema - Linux环境编程 - 2008-08-07 10:32:25 阅读(3803) 回复(6)

我写了一个tomcat监控和启动停止脚本,现在出现了点问题,请教高人指点一下,脚本如下 #!/bin/bash # # Startup script for the tomcat # # chkconfig: 345 95 15 # description: tomcat service script # # Source function library. . /etc/rc.d/init.d/functions TOMCAT_HOME=/opt/apache-tomcat-5.5.27 RETVAL=1 tomcat(){ source /etc/profile cd /root/ wget --quiet --timeout=1 --tries=2 --cache=off "http://test.g...

by lydongkill - Shell - 2009-11-16 14:18:46 阅读(7111) 回复(5)

脚本运行完没有出错返回0 ,出错返回1,将值传递给总控,请问怎么实现比较好 我有几个想法 1 用echo 如果脚本有错误,我就打印一个1,没有错误打印一个0,然后在让总控去调用(不知道怎么调用) 2 用exit 0 1 如果有错误,就exit 1 。没有错误就exit 0 但是总控怎么调用也不知道 请大家给我想想,怎么做比较好

by youkenn82 - Shell - 2013-10-28 17:56:08 阅读(2158) 回复(9)

我的一个shell脚本最后如下: checkcd #调用我自己写的一个函数 ret=$? if [ $ret -gt 1 ] ; then exit 0 else exit 1 我需要根据这个脚本返回值是0还是1来判断结果是否正确,但是我用exit 0,exit 1却出现错误: syntax error: unexpected end of file 请问这个返回值应该怎么写?谢谢指导!

by rockally - Shell - 2005-03-30 12:56:55 阅读(5448) 回复(4)

请教一下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" ...

by wdong_2001 - Shell - 2014-05-06 17:17:30 阅读(2525) 回复(8)

#!/bin/bash sum_test() { a=(("$1"+"$2")) return a } b=sum_test "$1" "$2" echo $b ./sum_test.sh 10 20 输出: sum_test 为什么不是30呢?

by hxl - Shell - 2010-06-10 15:26:41 阅读(5325) 回复(10)

执行 test.sh hello 结果 hello yes 我期待的结果是 hello no 为什么会这样? 哪位大大释下疑,谢了! 程序: test.sh #!/bin/sh show () { echo "$1" rtnval=$? if [ $rtnval -ne 0 ]; then echo "error" return 1 fi return 0 } if show $1 ; then echo "yes" else echo "no" fi

by sellie - Shell - 2010-03-04 19:03:22 阅读(3287) 回复(4)

我在perl中调用了shell脚本,想获取shell脚本返回值,如下: a.sh: #!/bin/sh list=(aa bb cc dd) if grep "aa" ${list[@]} then exit 1 fi b.pl: #!/usr/bin/perl -w use strict; `bash a.sh`; my $temp=`echo $?`; print $temp; 运行上面的结果,当a.sh返回0时,b.pl中$temp的值是0; 但是当a.sh返回1时,b.pl中$temp的值是256,为什么? [ 本帖最后由 jiangxue1327 于 2008-8-28 18:01 编辑 ]

by jiangxue1327 - Perl - 2011-12-25 13:02:41 阅读(7314) 回复(7)

我在linux下自己写了一个脚本,运行后可以返回结果,也能重定向到文件。但是在php下用exec调用后不能返回值,重定向到文件,文件建立了,但是没有内容,是怎么一回事啊!可是$rc是返回0,说明执行成功了,但怎么就是没有结果?谢谢各位大哥赐教! $command = "sh gateway.sh > /tmp/123456789.txt"; exec($command, $result, $rc); if ($rc != 0) die("命令操作失败!"); ...

by x.jc - Shell - 2007-09-14 21:33:26 阅读(2838) 回复(7)