linux shell 快速入門小例子(shell十三問學習NOTE)

來源:互聯網
上載者:User

標籤:shell

讀CU論壇shell十三問後進行的幾次小實驗,備忘一下!

SHELL十三問地址:http://bbs.chinaunix.net/thread-218853-1-1.html

#!/bin/bashfunction func_com(){        local a=1        local b="2c3"        echo ${a}b        echo $ab}function func_array(){        echo "##### func_array #####"        local PATH="/home/stone"        source $PATH/include/tt.ini        #echo $name        local srand=(1 3 5 2)        local srand_num=${#srand[*]}        for((i=0;i<$srand_num;i++));do        echo $((srand[i]+age))        done        echo "##### func_array #####"}function func_for(){        echo "##### func_for #####"        local bin_path="/usr"        local array=(2 3 5 7 9)        local array_n=${#array[*]}        for dir in $(ls $bin_path);        do        echo $dir        done        for ((i=0;i<$array_n;i++));        do        echo ${array[i]}        done        echo "##### func_for #####"}function func_getlen(){        echo "$#"}function func_param(){        echo "##### func_len \[email protected] #####"        func_getlen     "[email protected]"        echo "##### func_len \[email protected] #####"        echo "##### func_len \$* #####"        func_getlen     "$*"        echo "##### func_len \$* #####"}function func_calc(){        echo "##### func_calc \$* #####"        local a=$RANDOM        local b=4        local c=8        d=$((a+b))        echo $d        e=`expr $a + 7`        echo $e        echo "##### func_calc \$* #####"}function func_exit(){        local str1="abc"        local str2="def"        echo $str1        exit 0        echo $str2}function func_if(){        local a=1        local b=3        local str="abc"        if [ ! $a=1 ];then                echo "equal"        elif [[ $str="abc" ]]        then                echo "str equal"        else                echo "else"        fi}function func_read(){        op=""        while [[ $op != "q" ]]        do                read -p "input one word 'a,b,q'! " op                case $op in                a)                echo "the word is $op";;                b)                echo "b";;                q)                exit;;                *)                echo "input err!"                esac        done}function func_getopt(){        ARGS="`getopt -u -o "ht:a:n:"  -l "help,time:,age:,number:" -- "[email protected]"`"        [ $? -ne 0 ] && usage        set -- ${ARGS}        while [ true ] ;         do        case $1 in                -h|--help)                        usage                        shift                        ;;                -t|--time)                        echo "time is $2"                        shift                        ;;                -a|--age)                        echo "age is $2"                        shift                        ;;                -n|--number)                        echo "number is $2"                        shift                        ;;                --)                        shift                        break                        ;;                *)                        usage                        ;;        esac        shift        done}main(){        func_com        #func_for        #func_array        #func_param 1 a 2 b        #func_calc        #func_exit        #func_if        #func_read        #case while getopt         #func_getopt -t 20150320 -a 25 --number 88}main


linux shell 快速入門小例子(shell十三問學習NOTE)

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.