Shell Script (ii)

Source: Internet
Author: User

1.Until Loop statement

#!/bin/basha=10;until [[$a-lt 0]];d oecho $a;((a--));d one;

2.case Selection Statement

#!/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. Making a selection menu

#!/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. Select Menu Exit 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. Print multiplication Formula shell

#! /bin/bashfor i in ' seq 1 9 '; Do-J in ' seq 1 $i '; Do Echo-ne "${j}x${i}=$ (($i * $j)) \ t" done echodone
6.shell cut intercept Command-c list specifies the number of cut characters. The-f field specifies the number of clipping fields. -d Specifies a domain delimiter that differs from the space and the T a B key. -C is used to specify the clipping range, as follows:-C 1,5-7 cuts the 1th character, then the 5th to the 7th character. -C1-50 5 0 characters before clipping. The-f format is the same as-C. -F 1,5 Clipping 1th field, 5th field. -F 1,10-12 clipping 1th field, 1th 0 domain to 1th 2 domain. Example: cut-d:-f1/etc/passwd//with ":" As the delimiter, intercept the first column in the passwd cut-d:-f1,5/etc/passwd//Intercept the first and fifth columns


~
~


~
~

This article is from the "Fluffy Duck" blog, please be sure to keep this source http://woshitieren.blog.51cto.com/2466034/1669760

Shell Script (ii)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.