if [ $a -eq $b ]; then echo"$a -eq $b : a 等于 b" else echo"$a -eq $b: a 不等于 b" fi if [ $a -ne $b ]; then echo"$a -ne $b: a 不等于 b" else echo"$a -ne $b : a 等于 b" fi if [ $a -gt $b ]; then echo"$a -gt $b: a 大于 b" else echo"$a -gt $b: a 不大于 b" fi if [ $a -lt $b ]; then echo"$a -lt $b: a 小于 b" else echo"$a -lt $b: a 不小于 b" fi if [ $a -ge $b ]; then echo"$a -ge $b: a 大于或等于 b" else echo"$a -ge $b: a 小于 b" fi if [ $a -le $b ]; then echo"$a -le $b: a 小于或等于 b" else echo"$a -le $b: a 大于 b" fi
if [ -r $file ]; then echo"文件可读" else echo"文件不可读" fi if [ -w $file ]; then echo"文件可写" else echo"文件不可写" fi if [ -x $file ]; then echo"文件可执行" else echo"文件不可执行" fi if [ -f $file ]; then echo"文件为普通文件" else echo"文件为特殊文件" fi if [ -d $file ]; then echo"文件是个目录" else echo"文件不是个目录" fi if [ -s $file ]; then echo"文件不为空" else echo"文件为空" fi if [ -e $file ]; then echo"文件存在" else echo"文件不存在" fi
if [ $a = $b ]; then echo"$a = $b : a 等于 b" else echo"$a = $b: a 不等于 b" fi if [ $a != $b ]; then echo"$a != $b : a 不等于 b" else echo"$a != $b: a 等于 b" fi if [ -z $a ]; then echo"-z $a : 字符串长度为 0" else echo"-z $a : 字符串长度不为 0" fi if [ -n "$a" ]; then echo"-n $a : 字符串长度不为 0" else echo"-n $a : 字符串长度为 0" fi if [ $a ]; then echo"$a : 字符串不为空" else echo"$a : 字符串为空" fi
#!/bin/bash cd /root/tar ls *.tar.gz >tar.log ls *.tgz >>tar.log &>/dev/null line = $(cat tar.log |wc -l) for i in$line do tar -xzvf $i -C /root/tar done rm -rf tar.log
for (( i=1; i<"$line"; i++)) do num = $(cat tar.log |awk 'NR=='$i' {print $1}') tar -xzvf $num -C /root/tar done rm -rf tar.log --------------------------------------------------------- #!/bin/bash grep "<\([0-9]\{1,3\}\.\)\{3\}[0-9]\{1,3\}\>" /root/ip.txt >/root/iptest_1.txt grep "^[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}$" /root/ip.txt >/root/iptest_1.txt line = $(wc -l /root/iptest_1.txt awk '{print $1}') echo"" >/root/iptest.txt for (( i=1; i<=$line; i++)) do cat /root/iptest_1.txt |awk 'NR=='$i' {print}' >/root/iptest_2.txt a = $(cat /root/iptest_2.txt |cut -d '.' -f1) b = $(cat /root/iptest_2.txt |cut -d '.' -f2) c = $(cat /root/iptest_2.txt |cut -d '.' -f3) d = $(cat /root/iptest_2.txt |cut -d '.' -f4) if [ "$a" -lt 1 -o "$a" -gt 255 ]; then continue fi if [ "$b" -lt 0 -o "$b" -gt 255 ]; then continue fi if [ "$c" -lt 0 -o "$c" -gt 255 ]; then continue fi if [ "$d" -lt 0 -o "$d" -gt 255 ]; then continue fi cat /root/iptest_2.txt >>/root/iptest.txt done rm -rf /root/iptest_1.txt --------------------------------------------------------- #!/bin/bash read -t 30 -p "Please input users name:" NAME read -t 30 -p "Please input the number of users:" NUM read -t 30 -p "Please input the password of users name:" PASS if [ ! -z "$NAME" -a ! -z "$NUM" -a ! -z "$PASS"]; then TMP = $(echo$NUM |sed 's/[0-9]//g') if [ -z "$TMP" ]; then for(( i=1; i<$NUM; i=i+1)) do /usr/sbin/useradd $NAME$i &>/dev/null echo$PASS |/usr/bin/passwd --stdin $NAME$i &>/dev/null chage -d 0 $NAME$i &>/dev/null done fi fi --------------------------------------------------------- #!/bin/bash user = $(cat /etc/passwd |grep "/bin/bash" |grep -v "root" |cut -d ":" -f1) for i in$user do userdel -r $i done
while-do-done
1 2 3 4 5 6 7 8 9 10 11 12 13
#!/bin/bash i = 1 s = 0 while [ $i -le 100 ] do s = $(( $s + $i )) i = $(( $i + $1 )) done echo"The sum is: $s"