shell指令碼(二)

來源:互聯網
上載者:User

標籤:shell

1.Until迴圈語句

#!/bin/basha=10;until [[ $a -lt 0 ]];doecho $a ;((a--));done;

2.case 選擇語句

#!/bin/bash#auto install LAMP#by 2015-6-30case $1 in         apache )echo "wait for install httpd server..."yum install http* -y;;        mysql )echo -e "wait fo install mysql server..."        yum install mysql mysql-devel mysql-server -y        ;;        php )        echo "wait fo install php...."        yum install php php-server php-mysql -y        ;;        * )echo -e "\033[32mUsage:{$0 apache|mysql|php|help}\033[0m"              ;;esac

3.製作選擇菜單

#!/bin/bash#auto install LAMP#by 2015-6-30
PS3="select your will exec menu:"select i in "apache" "mysql" "php"docase $i in         apache )echo "wait for install httpd server..."yum install http* -y;;        mysql )echo -e "wait fo install mysql server..."        yum install mysql mysql-devel mysql-server -y        ;;        php )        echo "wait fo install php...."        yum install php php-server php-mysql -y        ;;        * )echo -e "\033[32mUsage:{$0 apache|mysql|php|help}\033[0m"        ;;esacdone

~ 4.選擇菜單退出shell

#!/bin/bashPS3="select a meau:"echo -e "\033[32mPlease chose a commend to run\033[22m"select i  in  "w" "top" "ifconfig" "free" "quit"        do        case    $i in        w)        w;exit        ;;        top)        top;exit        ;;        ifconfig)        ifconfig;exit        ;;        free)        free -m;exit        ;;        quit )        exit        ;;        *)echo -e"\033[32mPlease input a number:\033[0m"  ;;esacdone

5.列印乘法口訣shell

#! /bin/bashfor i in `seq 1 9`; do        for j in `seq 1 $i`; do                echo -ne  "${j}x${i}=$(($i*$j))\t"        done        echodone
    6.shell中cut截取命令-c list 指定剪下字元數。-f field 指定剪下域數。-d 指定與空格和t a b鍵不同的域分隔字元。- c用來指定剪下範圍,如下所示:- c 1,5-7 剪下第1個字元,然後是第5到第7個字元。-c1-50 剪下前5 0個字元。-f 格式與- c相同。-f 1,5 剪下第1域,第5域。- f 1,10-12 剪下第1域,第1 0域到第1 2域。例子:cut -d: -f1  /etc/passwd  //以“:”為分隔字元,截取passwd中第一列cut -d: -f1,5   /etc/passwd  //截取第一列和第五列

                
~                                                                                                                                  
~                         

                                                                                                                                 
~                                                                                                                                  
~                         

本文出自 “毛毛鴨” 部落格,請務必保留此出處http://woshitieren.blog.51cto.com/2466034/1669760

shell指令碼(二)

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.