亚洲免费在线-亚洲免费在线播放-亚洲免费在线观看-亚洲免费在线观看视频-亚洲免费在线看-亚洲免费在线视频

Linux Shell學習簡單小結(更新中……)

系統 3402 0

if-fi

Result:

(沒有readme文件)

[work shell]$ sh if_e.sh
add readme ...
[workshell]$ sh if_e.sh
del readme ...
add readme ...

===================================================

if-else-fi

Result:

[work shell]$ sh if.sh
press y hello
y
hello
[work shell]$ sh if.sh
press y hello
n
bye..

===================================================

if-elif-else-if(函數傳參1)

    # !/bin/sh

type=1    # 1, 2, 3(a,abc,123)


function getVal(){
    echo "$1"
}


if [ "$type" == "1" ]; then
    for((i=0;i<4;i++))
    do
        eval getVal $i
    done
elif [ "$type" == "2" ]; then
    echo "type"
else
    echo "none"
fi

  
Result:

yanggang@barry$ ./param.sh
0
1
2

3

===================================================

if-elif-else-if(函數傳參2)

    # !/bin/sh

#type=1    # 1, 2, 3(a,abc,123)


function getVal(){
    echo "$1"
}

function inputVal(){
    if [ "$1" == "1" ]; then
        for((i=0;i<4;i++))
        do
            eval getVal $i
        done
    elif [ "$1" == "2" ]; then
        echo "type"
    else
        echo "none"
    fi
}

inputVal 1      # 1 is a param
  

Result:

yanggang@barry$ ./param.sh

0
1
2

3

===================================================

case 條件

mysql

    #!/bin/bash

case "$1" in
    start)
        echo "mysql start..."
        /etc/init.d/mysqld start
        ;;
    stop)
        echo "mysql stop..."
        /etc/init.d/mysqld stop
        ;;
    restart)
        echo "mysql restart..."
        /etc/init.d/mysqld stop
        /etc/init.d/mysqld start
        ;;
esac

exit 0
  

httpd (apache)

    #!/bin/bash

case "$1" in
    start)
        echo "apache start..."
        /etc/init.d/httpd start
        ;;
    stop)
        echo "apache stop..."
        /etc/init.d/httpd stop
        ;;
    restart)
        echo "apache restart..."
        /etc/init.d/httpd restart
        ;;
    status)
        echo "apache status"
        /etc/init.d/httpd status
        ;;
esac

exit 0
  

===================================================

awk

Result:

[work]$ sh cal_lines.sh
ls: *.h: No such file or directory
91 test_performance_server.cpp
178 test_performance_ubclient1.cpp
230 test_performance_ubclient2_common_async.cpp
204 test_performance_ubclient2_common_block.cpp
206 test_performance_ubclient2_common_nonblock.cpp
191 test_performance_ubclient2_common_single_block.cpp
193 test_performance_ubclient2_common_single_nonblock.cpp
237 test_performance_ubclient2_nshead_async.cpp
220 test_performance_ubclient2_nshead_block.cpp
218 test_performance_ubclient2_nshead_nonblock.cpp
192 test_performance_ubclient2_nshead_single_block.cpp
192 test_performance_ubclient2_nshead_single_nonblock.cpp
2352

===================================================

linux實現兩個文件內容相加(3種解法)

a.txt(10行) b.txt(9行)

a.txt Linux Shell學習簡單小結(更新中……) b.txt

解法一

運行結果:

[work]$ sh cal_ab1.sh
1 83
1 77
0 128
24 195
1 130
68 227
5 132
197 233
9 146

--------------------------------------------------------------------------------------

解法二

運行結果:

[work]$ sh cal_ab2.sh
1 83
1 77
0 128
24 195
1 130
68 227
5 132
197 233
9 146
0 8

--------------------------------------------------------------------------------------

解法三

運行結果:

[work]$ sh cal_ab3.sh
1 83
1 77
0 128
24 195
1 130
68 227
5 132
197 233
9 146
0 8

--------------------------------------------------------------------------------------

評析:

解法一,結果不準確,只輸出了前9行

解法二,結果正確,但不夠簡潔

解法三,結果正確,簡潔

===================================================

while循環

    # !/bin/sh

TOP_NUM=800
index=0


function url_down(){

while [ $index -le $TOP_NUM ]
    do
       echo $index
        index=`expr $index + 24`
done

}

url_down
  

運行結果:

yanggang@barry$ ./tmp.sh
0
24
48
72
96
120
144
168
192
216
240
264
288
312
336
360
384
408
432
456
480
504
528
552
576
600
624
648
672
696
720
744
768
792

-------------------------------------------------------------------------------

參考拓展:

Linux Make(Makefile)由淺入深的學習與示例剖析

shell if語句 示例:文件或目錄是否存在或有執行權限

linux實現兩個文件內容相加

awk中NR與FNR

百度面試及總結4

shell基礎知識

關于RANDOM 的例子

shell函數(傳參)的使用

參考推薦:
Linux Shell函數返回值

Linux 之 shell 比較運算符 (推薦)

Linux Shell學習簡單小結 (推薦)

SHELL學習筆記----IF條件判斷,判斷條件


===================================================

Linux Shell學習簡單小結(更新中……)


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦?。?!

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 伊人精品在线 | 亚洲精品国精品久久99热 | 国产精品亚洲精品一区二区三区 | 国产精品亚洲一区二区在线观看 | 亚洲综合色就色手机在线观看 | 五月婷婷国产 | 日本精品视频网站 | 884hutv四虎永久黄网 | 国产亚洲精品精品国产亚洲综合 | 亚洲激情小视频 | 亚洲七七久久精品中文国产 | 欧美欧美aaaaa一级毛片 | 四虎国产免费 | a毛片在线播放 | 四虎影院永久 | 4hu四虎免费影院www | 天天操夜夜操狠狠操 | 久操免费在线观看 | 亚洲国产第一区二区香蕉 | 亚洲欧洲日韩国产一区二区三区 | 可以免费观看的一级毛片 | 97影院官网| 久久久久久久国产精品毛片 | 免费一级特黄欧美大片勹久久网 | 欧美激情aa毛片 | 国产一级毛片外aaaa | 亚洲综合区小说区激情区噜噜 | 俄罗斯一级毛片免费播放 | 欧美真人视频一级毛片 | 91综合久久婷婷久久 | 久久精品国产第一区二区 | 久久精品国产精品亚洲精品 | 综合伊人 | 久久一本久综合久久爱 | 国产精品免费观看 | 欧美一区二区在线免费观看 | 91尤物视频| 久久成人综合网 | 国产成人毛片视频不卡在线 | 国产在线观看精品香蕉v区 国产在线观看美女福利精 国产在线观看午夜不卡 | 涩涩www在线观看免费高清 |