ChinaUnix.net
相关文章推荐:

shell 脚本返回值

我写了一个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 阅读(7845) 回复(5)

相关讨论

本帖最后由 奋斗的毛毛虫 于 2015-11-02 10:55 编辑 鄙人编写了一个shell脚本,运行脚本之后,可以通过执行命令:echo $?查看脚本执行返回值;所以鄙人想在脚本执行到指定步骤指定脚本返回值。 注: flag=0 ------> 不退出程序 flag=1 ------> 不退出程序 flag=2 ------> 退出程序 请大家帮忙我一下,谢谢。 注:在脚本结束之后,运行echo $?查看脚本返回值,这个值是我在脚本中指定的。

by 奋斗的毛毛虫 - Shell - 2015-11-02 15:18:08 阅读(1307) 回复(3)

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

by youkenn82 - Shell - 2013-10-28 17:56:08 阅读(2600) 回复(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 阅读(6271) 回复(4)

执行 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 阅读(3547) 回复(4)

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 阅读(4103) 回复(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 阅读(8394) 回复(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 阅读(3140) 回复(7)

如果我想在function中返回两个值,应该怎么写,下面就是测试脚本,我想返回给main主程序 return listener和 return 1这两个值,这样写好像不行。test是另外一个function. test if [ $? = 1 ] then listener = 2 return listener return 1 fi 谢谢!

by xubbyy - Shell - 2004-12-07 10:33:55 阅读(2073) 回复(1)

我的一个程序(tcl)中,需要调用另一个shell脚本文件,我希望这段shell脚本能够返回一个值(字符串),我在tcl程序中需要使用。不知能不能有返回值?? 当然写临时文件可以达到这个目的,能不能直接让shell脚本返回值??

by GanQuan - Shell - 2003-08-19 13:22:01 阅读(10034) 回复(3)

我写了一个编译脚本,如果文件类型是c或者cpp就直接编译单个文件,函数如下: [code] func Compile() if &filetype == 'c' let cc = 'gcc' elseif &filetype == 'cpp' let cc = 'g++' else echo &filetype . ' : 该文件不是C/C++程序。' return endif call UpdateTags() let tmp=tempname() exec '!' . cc . ' -Wall -lm % -o %< 2>' . tmp . ' ; export ret=$?' exec '! echo ' . cc . '返回: $ret >>' . tmp...

by starwing83 - C/C++ - 2008-08-29 21:26:13 阅读(3580) 回复(3)