sehll中函数返回值范围

来源:互联网 发布:java生成多个随机数 编辑:程序博客网 时间:2024/05/26 22:57
通过下面的例子可以测试出shell中函数return的返回值为0--255
#!/bin/bash
#find the max one of two numbers
PARAM_ERR=256
PARAM_EQU=0
max2 ()
{
    if [ -z "$2" ]
    then
    return $PARAM_ERR
    fi
    
    if [ "$1" -eq "$2" ]
    then
    return $PARAM_EQU
    fi

    if [ "$1" -gt "$2" ]
    then
    return $1
    else
    return $2
    fi
}

max2 98 88
return_val=$?
if [ "$return_val" -eq "$PARAM_ERR" ]
then
echo "Need parameter"
elif [ "$return_val" -eq "$PARAM_EQU" ]
then
echo "They are equal"
else
echo "The max number is $return_val"
fi
 
<script>window._bd_share_config={"common":{"bdSnsKey":{},"bdText":"","bdMini":"2","bdMiniList":false,"bdPic":"","bdStyle":"0","bdSize":"16"},"share":{}};with(document)0[(getElementsByTagName('head')[0]||body).appendChild(createElement('script')).src='http://bdimg.share.baidu.com/static/api/js/share.js?v=89860593.js?cdnversion='+~(-new Date()/36e5)];</script>
阅读(659) | 评论(0) | 转发(0) |
0

上一篇:Bash shell中的位置参数$#,$*,$@,$0,$1,$2...及特殊参数$?,$-等的含义

下一篇:expr用法

相关热门文章
  • Qt学习笔记---信号与槽...
  • c++防止隐藏的拷贝构造...
  • app开发需要多少钱
  • c++ virtual析构函数详解...
  • QEMU源码分析系列(三) ...
  • linux 常见服务端口
  • xmanager 2.0 for linux配置
  • 【ROOTFS搭建】busybox的httpd...
  • openwrt中luci学习笔记
  • 什么是shell
  • linux dhcp peizhi roc
  • 关于Unix文件的软链接
  • 求教这个命令什么意思,我是新...
  • sed -e "/grep/d" 是什么意思...
  • 谁能够帮我解决LINUX 2.6 10...
给主人留下些什么吧!~~
原创粉丝点击