標籤: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指令碼(二)