語法
注意:*不能加雙引號
#!/bin/bash
read -p "Please input tour name : " -t 30 name
case $name in
"Finley")
echo "Hello,Finley ,welcome !!"
;;
"Lin")
echo "Hello , Mrs.He ,welcome !!"
;;
"*")
echo "Please dont use the computer,it is not yours"
;;
esac
[root@localhost shelltest]# ./case.sh
Please input tour name : Finley
Hello,Finley ,welcome !!
[root@localhost shelltest]# ./case.sh '
> ;
> dquit
> exit
> ^C
[root@localhost shelltest]# ./case.sh
Please input tour name : dslfd
Please dont use the computer,it is not your
[root@localhost shelltest]# ./girlf.sh
1 | fengjie
2 | canglaoshi
3 | boduoye
please input your choice: 1
your choice is fengjie!!
[root@localhost shelltest]# ./girlf.sh
1 | fengjie
2 | canglaoshi
3 | boduoye
please input your choice: 2
your choice is canglaoshi!!!
[root@localhost shelltest]# ./girlf.sh
1 | fengjie
2 | canglaoshi
3 | boduoye
please input your choice: 3
your choice is doduoye!!!
[root@localhost shelltest]#
#!/bin/bash
echo " 1 | fengjie "
echo " 2 | canglaoshi "
echo " 3 | boduoye "
read -p "please input your choice: " -t 30 girl
case "$girl" in
"1")
echo "your choice is fengjie!!"
;;
"2")
echo "your choice is canglaoshi!!!"
;;
"3")
echo "your choice is doduoye!!!"
;;
*)
echo "error input !!"
;;
esac
特別提醒:
/dev/null如同linux系統的回收站一般
#!/bin/bash
cd /opt/shelltest
touch ls.log
ls *.sh | grep -v deltest.sh > ls.log
ls *.txt>>ls.log
for i in $(cat ls.log)
do
rm -rf $i &> /dev/null
done
rm -rf ls.log
[root@localhost shelltest]# vim deltest.sh
[root@localhost shelltest]# ./deltest.sh
[root@localhost shelltest]# ls
deltest.sh
#############################################################################################
# File Name: for.sh
# Author: Finley
# mail: [email protected]
# Create Time: Wed 21 Aug 2019 09:50:09 AM CST
#====================================================================================
#!/bin/bash
declare -i i=0
for (( i=0;i<=100; i++))
do
echo "$i "
done
之前是怎麼寫都出錯,後來發現,在雙小括號裏面,可以用我們在C語言,C++裏面一樣的表達式:
declare -i i=0
for (( i=0;i "
done
一開始是這樣寫的,發現怎麼寫都不對