1.判断字符串为空 if [ -z "$str" ]; then echo "empty string" fi 2.判断文件是否存在 if [ -f /home/builder/.profile ]; then echo "File exists;" fi 3.逻辑非 if [ ! -f /home/builder/.bash_profile ]; then echo "here!"else echo "te
test.sh #!/bin/bash s1="" if test $s1 ;then echo "length is not zero" else echo "the length is 0" fi s2="shell" if test $s2 ;then echo "length is not 0" else echo "the length is 0" fi 执行 sudo chm
test.sh #!/bin/bash echo "enter the string:" read filename if test -z $filename ; then echo "the length is 0" else echo "the length is not 0" fi 执行 sudo chmod +x test.sh./test.sh 输出 enter the string: the length 执行 ./test.sh 输
1.使用grep s1="abcdefg" s2="bcd" result=$(echo $s1 | grep "${s2}") if [[ "$result" != "" ]] then echo "$s1 include $s2" else echo "$1 not include $s2" fi 2. 使用操作符~ fileName=/home/sss/data