zoukankan      html  css  js  c++  java
  • shell常见语法

    #!/bin/bash
    echo "**********argument**********"
    echo script name: $0
    echo first argument $1
    echo second argument $2
    echo num of argument $#
    echo all argument $@

    #function
    equal()
    {
      case $1 in
      $2)
        return 0
      ;;
      *)
        return 1
      ;;
      esac
    }

    #if
    echo "**********test if**********"
    if equal $1 $2;
    then
      echo "equal"
    else
      echo "not equal"
    fi

    if [ $# -gt 0 ];
    then
      echo number of argument greater than 0
      echo $@
    else
      echo number of argument is 0
    fi

    #for
    echo "**********test for**********"
    for i in $@
    do
      echo $i
    done
    LIMIT=5
    for (( a=1; a<=$LIMIT; a++ ))
    do
      echo "$a"
    done

    #while
    echo "**********test while**********"
    a=0
    LIMIT=10
    while [ $a -lt $LIMIT ]
    do
      echo $a
      a=$((a+1))
    done

    #case
    echo "**********test case**********"
    read -p "press some key, then press return:" KEY
    case $KEY in
    [a-zA-Z])
      echo "It's a letter!"
      ;;
    [0-9])
      echo "It's a number!"
      ;;
    *)
      echo "other key!"
      ;;
    esac

    #printf
    echo "**********test printf**********"
    x=abc; printf "x is now: %s, Enter new value:" $x; read x

    运行./test.sh 1 1结果如下:

  • 相关阅读:
    线性时间选择
    ios理解 Pro Mutlithreading and Memory Management for iOS and OS X with ARC, Grand Central Dispatch, and Blocks
    ef
    c# 采集 获取网页数据内容 一会超时的问题
    entity4.1
    逐渐约束
    entity4.1
    ObjectContext.Refresh
    使用内存表
    MVCdropdownlist
  • 原文地址:https://www.cnblogs.com/fellow1988/p/6143068.html
Copyright © 2011-2022 走看看