• 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结果如下:

  • 相关阅读:
    05-浮动/css
    04-选择器/css
    03-样式表/css
    02-html标签&表格&表单
    01-html基础&标签
    vue分页组件重置到首页问题
    VUE通过索引值获取数据不渲染的问题
    常见IE8兼容性问题及解决
    Ajax
    sea.js模块化工具
  • 原文地址:https://www.cnblogs.com/fellow1988/p/6143068.html
Copyright © 2020-2023  润新知