IT博客汇
  • 首页
  • 精华
  • 技术
  • 设计
  • 资讯
  • 扯淡
  • 权利声明
  • 登录 注册

    SHELL:某个数值是否在列表之中?

    Adamhuan发表于 2017-04-26 03:20:43
    love 0

    代码:

    [root@oracle-cluster-3 shell]# cat match_list.sh 
    list_a="2 3 5 67 90"
    current_num=91
    after_all=108
    
    is_in="no"
    
    for list_item in $list_a
    do
    
      #echo "current in list is: [$list_item]"
    
      if [ $list_item -gt $current_num ]
      then
        is_in="yes"
      fi
    
      #echo ""
    
    done
    
    echo "current num is: [$current_num]"
    echo "does current num in the list? [$is_in]"
    [root@oracle-cluster-3 shell]# 
    [root@oracle-cluster-3 shell]# sh match_list.sh 
    current num is: [91]
    does current num in the list? [no]
    [root@oracle-cluster-3 shell]# 
    [root@oracle-cluster-3 shell]#

    ——————————————
    Done。



沪ICP备19023445号-2号
友情链接