echo "The file exists and is not empty." fi So, what is this script doing? The code [ -e "$FILE" ] checks if the file exists, then [ ! -s "$FILE" ] checks if the file is not of size greater than zero (i.e., it is empty). The "elif" (else if) part handles the cas...
abc : The string is not empty 文件测试运算符 实例: #!/bin/bash file="/home/shiyanlou/test.sh" if [ -r $file ] then echo "The file is readable" else echo "The file is not readable" fi if [ -e $file ] then echo "File exists" else echo "File not exists" fi 结果 The file ...
if[ -n"$empty_string"];then echo"empty string is non_empty" fi if[ -e"${HOME}/.fvwmrc"];then# test to see if ~/.fvwmrc exists echo"you have a .fvwmrc file" if[ -L"${HOME}/.fvwmrc"];then# is it a symlink ? echo"it's a symbolic link elif[ -f"${HOME}/.fvwmrc"]...
-r FILE_NAM # True if FILE_NAM is readable -s FILE_NAM # True if FILE_NAM exists and is not empty -w FILE_NAM # True if FILE_NAM has write permission -x FILE_NAM # True if FILE_NAM is executable 字符串测试操作 -z STRING # True if STRING is empty -n STRING # True if STRI...
or if a file is readable (not corrupted, have permissions, etc.):canread() { [ -r "$1" ]; } or if it is a directory:isdir() { [ -d "$1" ]; } or is writable for the current user:canwrite() { [ -w "$1" ]; } or if a file exists and is not empty (like a lo...
is readable-s FILE_NAM # TrueifFILE_NAM existsandisnotempty-w FILE_NAM # TrueifFILE_NAM has write permission-x FILE_NAM # TrueifFILE_NAM is executable#字符串测试操作-z STRING # TrueifSTRING is empty-n STRING # TrueifSTRING isnotemptySTRING1...
bash 中的 source 命令用于在当前 bash 环境下读取并执行 FileName.sh 中的命令。 source test.sh . test.sh 引号 双引号(") “STRING” 将会阻止(解释)STRING 中大部分特殊的字符。后面的实验会详细说明。 单引号(’) ‘STRING’ 将会阻止 STRING 中所有特殊字符的解释,这是一种比使用"更强烈的形式。后面...
附件: bash的if语句语法 if [ conditional-expression1 ]; then statement... elif [ conditional-expression2 ]; then statement... else statement... fi 注意关键字then可以换行起,但我个人还是喜欢放在同一行。 条件表达式 conditional-expression -nSTRINGThelength ofSTRINGisgreater than zero.-zSTRINGTheleng...
-f file True if file exists and is a regular file. So: if [ -f someFileName ]; then echo 'Found some!'; fi Edit: I see you already got the answer, but for completeness, you can use the info in Checking from shell script if a directory contains files - and lose the dotglob...
-n abc : The string length is not 0 abc : The string is not empty 1. 2. 3. 文件测试运算符 实例: #!/bin/bash file="/home/shiyanlou/test.sh" if [ -r $file ] then echo "The file is readable" else echo "The file is not readable" ...