1、SHELL編程Case語句案例實戰
1)Case選擇條件語句的格式:
case $INPUT in Pattern1) 語句1 ;; Pattern2) 語句2 ;; esac
2)Case語句企業案例實戰一:
case $1 in 1) wget -c http://nginx.org/download/nginx-1.16.0.tar.gz ;; esac
2、SHELL編程Select語句案例實戰
1)Select選擇菜單語句的格式:
select i in redhat centos ubuntu suse(菜單名) do echo $idone
2)Select語句企業案例實戰一:
#!/bin/bash PS3="What you like most of the open source system? " select i in redhat centos ubuntu suse do echo "Your Select OS is " $i done
3)Select&Case語句企業案例實戰二:
#!/bin/bash PS3="What you like most of the open source system? " select i in redhat centos ubuntu suse do case $i in redhat) echo "redhat linux" ;; centos) echo "centos linux" ;; ubuntu) echo "ubuntu linux";; suse) echo "suse linux" ;; *) exit esac done
3、SHELL編程Find語句案例實戰
1)SHELL編程四劍客工具:Find、Grep、Sed、Awk,通過四劍客可以完成常
規Linux指令無法完成或者比較復雜的功能,學好SHELL編程四劍客有助於
SHELL編程能力再上一層樓。
2)SHELL編程四劍客之一的Find工具,主要是用於Linux操作系統去查找某個文
件和目錄所在的位置的(絕對路徑),Find工具的語法格式:
find(工具) path(路徑) -option(參數) -action(動作); find path -option [ -print ] [ -exec -ok command ]
Path路徑:給定find工具一個大概的范圍,從哪個范圍去查找;
Option參數:按照某些特征:-name、-size、-mtime、-user;
Action動作:找到文件或者目錄之后執行的操作的動作(打印、執行);
3)SHELL編程四劍客Find工具案例操作一,基於Find工具查找Linux系統下
eth0網卡配置文件所在的路徑。
find / -name eth0find / -name ifcfg-eth0 find / -name "*eth0" find /etc/ -name "*eth0" find /etc/sysconfig/network-scripts/ -name "*eth0"
4)SHELL編程四劍客Find工具案例操作二,基於Find工具查找Linux系統下
auto_mysql_backup.sh所在的路徑。
find / -name auto_mysql_backup.sh find / -name *mysql_backup*.sh
5)SHELL編程四劍客Find工具案例操作三,基於Find工具查找Linux系統下
以.rpm結尾的軟件包,並且找到以mariadb命名開頭的包,排除mariadb-libs
包。
find / -name "*.rpm" find / -name "mariadb*rpm" find / -name "*.rpm" -a -name "mariadb*" find / -name "*.rpm" -name "mariadb*" ! -name "mariadb-libs*" find / -name "*.rpm" -a -name "mariadb*" -a ! -name "mariadb-libs*
6)SHELL編程四劍客Find工具案例操作四,基於Find工具查找Linux系統下
以.rpm結尾的軟件包,並且找到以mariadb命名開頭的包,排除mariadb-libs
包,並且將剩余軟件包拷貝至/tmp/目錄。
for soft in `find / -name "*.rpm" -name "mariadb*" ! -name "mariadb-libs*"`;do cp $soft /tmp/;done cp `find / -name "*.rpm" -name "mariadb*" ! -name "mariadb-libs*"` /tmp/ \cp $(find / -name "*.rpm" -name "mariadb*" ! -name "mariadb-libs*") /tmp/ find / -name "*.rpm" -name "mariadb*" ! -name "mariadb-libs*" -exec cp {} /tmp/ \; find / -name "*.rpm" -name "mariadb*" ! -name "mariadb-libs*"|xargs -I {}cp {} /tmp/