hellopasswdphp
[root@localhost ~]# cd shell/ [root@localhost shell]# vi 1.sh 添加 1 #!/bin/bash 2 f="/tmp/user" 3 if [ -f $f ] 4 then 5 echo $f exist 6 else 7 touch $f 8 fi [root@localhost shell]# sh -x 1.sh + f=/tmp/user + '[' -f /tmp/user ']' + touch /tmp/user [root@localhost shell]# ls /tmp/ ks-script-WBlSuE mysql.sock pear php-fcgi.sock user yum.log [root@localhost shell]# [root@localhost shell]# [root@localhost shell]# [root@localhost shell]# [root@localhost shell]# sh -x 1.sh + f=/tmp/user + '[' -f /tmp/user ']' + echo /tmp/user exist /tmp/user exist [root@localhost shell]# ls /tmp/ ks-script-WBlSuE mysql.sock pear php-fcgi.sock user yum.log
[root@localhost shell]# vi 1.sh 添加 1 #!/bin/bash 2 f="/tmp/user" 3 if [ -d $f ] 4 then 5 echo $f exist 6 else 7 mkdir $f 8 fi
[root@localhost shell]# vi 1.sh 添加 1 #!/bin/bash 2 f="/tmp/user/" 3 if [ -e $f ] 4 then 5 echo $f exist 6 else 7 mkdir $f 8 fi
[root@localhost ~]# cd shell/ [root@localhost shell]# ls 1.sh [root@localhost shell]# if [ -n 1.sh ]; then echo ok; fi ok [root@localhost shell]# echo $b [root@localhost shell]# if [ -n "$b" ]; then echo $b; else echo "b is null"; fi b is null
[root@localhost shell]# vi 1.sh 添加 1 #!/bin/bash 2 n=`wc -l /tmp/1.txt` 3 if [ -z "$n" ] 4 then 5 echo error 6 exit 7 else 8 if [ $n -gt 100 ] 9 then 10 echo ok 11 fi 12 fi
能夠改成mysql
[root@localhost shell]# vi 1.sh 添加 1 #!/bin/bash 2 n=`wc -l /tmp/1.txt` 3 if [ -z "$n" ] 4 then 5 echo error 6 exit 7 elif [ $n -gt 100 ] 8 then 9 echo ok 10 fi [root@localhost shell]# sh -x 1.sh ++ wc -l /tmp/1.txt wc: /tmp/1.txt: No such file or directory + n= + '[' -z '' ']' + echo error error + exit [root@localhost shell]# ls /tmp/ ks-script-WBlSuE mysql.sock pear php-fcgi.sock user yum.log
1 #!/bin/bash 2 if [ ! -f /tmp/1.txt ] 3 then 4 echo "/tmp/1.txt nnot exist." 5 exit 6 fi 7 n=`wc -l /tmp/1.txt` 8 if [ -z "$n" ] 9 then 10 echo error 11 exit 12 elif [ $n -gt 100 ] 13 then 14 echo ok 15 fi [root@localhost shell]# sh -x 1.sh + '[' '!' -f /tmp/1.txt ']' + echo '/tmp/1.txt nnot exist.' /tmp/1.txt nnot exist. + exit
使用變量時建議用雙引號標註sql
[root@localhost shell]# if grep -w 'user1' /etc/passwd; then echo "user1 exist"; fi [root@localhost shell]# if ! grep -w 'user1' /etc/passwd; then echo "user1 exist"; fi user1 exist
修改於 180207shell