需求说明: 在写脚本的时候,有的时候,需要判断一个字符串是否为空,因此,在此写出如何判断一个字符串为空的方法. 简单来说,就是字符串的比较. 测试脚本: 以下的脚本用于测试str_1和str_2是否是空字符串: #!/bin/bash str_1='' str_2=Badboy if [[ -z $str_1 ]]; then echo str_1 is empty. else echo str_1 is not empty. fi if [[ -z v$str_2 ]]; then echo
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