zoukankan      html  css  js  c++  java
  • 数学思想方法-分布式计算-linux/unix技术基础(5)

    shell命令行参数

    -bash-4.2$ cat test1.sh
    #!/bin/sh
    echo "$0  "
    echo "$1  "
    echo "$2  "


    -bash-4.2$ ./test1.sh a b c
    ./test1.sh  
    a  
    b  
    -bash-4.2$ 

    本博客全部内容是原创,假设转载请注明来源

    http://blog.csdn.net/myhaspl/


    显示全部命令行參数

    -bash-4.2$ cat test1.sh
    #!/bin/sh
    until [ -z "$1" ]
    do
       echo "$1  "
       shift
    done
    -bash-4.2$ ./test1.sh a b c d e f
    a  
    b  
    c  
    d  
    e  

    -bash-4.2$ cat test1.sh
    #!/bin/sh
    index=1
    for myarg in $*
    do
       echo "NO#$index=$myarg"
       let "index+=1"
    done
    -bash-4.2$ ./test1.sh a b c d e f
    NO#1=a
    NO#2=b
    NO#3=c
    NO#4=d
    NO#5=e
    NO#6=f
    -bash-4.2$ 


    条件表达式

    -bash-4.2$ cat test1.sh
    #!/bin/sh
    a=1
    b=2
    if [ $a -gt $b ]
    then
       echo "GT"
    else
       echo "LT"
    fi
    -bash-4.2$ ./test1.sh
    LT
    -bash-4.2$ 

    -bash-4.2$ cat test1.sh
    #!/bin/sh
    a=2
    b=2
    if [ $a -gt $b ]
    then
       echo "GT"
    elif [ $a -eq $b ]
    then
       echo "eq"
    else
       echo "LT"
    fi
    -bash-4.2$ ./test1.sh
    eq
    -bash-4.2$ 


    -bash-4.2$ cat test1.sh
    #!/bin/sh
    echo "====================="
    echo "1.a"
    echo "2.b"
    echo "3.c"
    read  mychoice
    case $mychoice in
         1 ) echo "a";;
         2 ) echo "b";;
         3 ) echo "c";;
    esac
    exit 0
    -bash-4.2$ ./test1.sh
    =====================
    1.a
    2.b
    3.c
    2
    b
    -bash-4.2$ 

    循环

    -bash-4.2$ cat test1.sh
    #!/bin/sh
    for filename in `ls`
    do
        echo $filename
    done
    -bash-4.2$ ./test1.sh
    1
    abc
    abd
    error.log
    hadoop-2.4.1
    hadoop-2.4.1-src.tar.gz
    hadoop-2.4.1.tar.gz
    hello
    mydoclist

    显示全部偶数

    :true都表示为真的意思

    -bash-4.2$ cat test1.sh

    #!/bin/sh

    a=0

    while :

    do

      let "a=$a + 1"

       if[ $a -gt 20 ]

      then

         break

       fi

       if[ $(($a%2)) -eq  1 ]

      then

         continue

       fi

      echo $a

    done  

    -bash-4.2$ ./test1.sh

    2

    4

    6

    8

    10

    12

    14

    16

    18

    20

    -bash-4.2$


  • 相关阅读:
    高可用Redis服务架构分析与搭建
    Java 程序性能问题
    限流、熔断、服务降级理解
    设计模式-享元设计
    设计模式-原型设计
    java8 Stream原理
    SQL语句性能优化策略
    OAuth2和JWT
    5种常见的Docker Compose错误
    leetcode_699. 掉落的方块
  • 原文地址:https://www.cnblogs.com/yxwkf/p/5041057.html
Copyright © 2011-2022 走看看