zoukankan      html  css  js  c++  java
  • Shell 三个小程序

    运行环境:Ubuntu12.04  bin/bash

    1.比较两个数的大小

    #!bin.bash
    #script4.4.sht
    echo "Enter the first integer:"
    read first 
    echo "Enter the second integer:"
    read second
    if [ "$first" -gt "$second" ]
        then 
            echo  "$first is greater than $second"
        elif [ "$first" -lt "$second" ]
    then
        echo "$first is less than  $second"
    fi
     


    2.判断当前用户是否和输入的用户名一致

    #!bin/bash
    #script4.3.sht
       echo  -n  "Enter your login name: "
       read name
       if [ "$name" = "$USER" ];
       then 
           echo "Hello,$name,how are you today?"
       else
           echo "If you are not user,who are you?"
       fi

    3.求若干数中的最小值

    #!bin/bash
    #script 4.8.sht
    smallest=10000
    for i in 12 5 18 58 -3 80
    do 
    if test $i -lt $smallest
    then 
        smallest=$i
    fi 
    done 
    echo " The smallest number is :$smallest"

    版权声明:本文为博主原创文章,未经博主允许不得转载。

  • 相关阅读:
    fiddler抓取java系程序的网络通信
    ZOJ 2724 Windows Message Queue(优先队列)
    FZU 电动车通行证制度
    Havel定理
    Catch That Cow
    Trie树
    zoj 2876 Phone List
    zoj 2420
    getchar
    zoj 1315 Excuses, Excuses!
  • 原文地址:https://www.cnblogs.com/Tobyuyu/p/4965376.html
Copyright © 2011-2022 走看看