-e = True if file exists -f = True if file exists and is a regular file -s = True if file exists and is NOT empty -r = True if file is readable by you -w = True if file is writable by you -x = True if file is executable by youString...
[ -f FILE ] True if FILE exists and is a regular file. [ -d FILE ] True if FILE exists and is a directory. [ -s FILE ] True if FILE exists and not empty (size more than 0). [ -r FILE ] True if FILE exists and is readable. [ -w FILE ] True if FILE exists and is ...
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 ...
-e FILE_NAM # True if FILE_NAM exists -f FILE_NAM # True if FILE_NAM exists and is a regular file -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...
bash 中的 source 命令用于在当前 bash 环境下读取并执行 FileName.sh 中的命令。 source test.sh . test.sh 引号 双引号(") “STRING” 将会阻止(解释)STRING 中大部分特殊的字符。后面的实验会详细说明。 单引号(’) ‘STRING’ 将会阻止 STRING 中所有特殊字符的解释,这是一种比使用"更强烈的形式。后面...
[[ FILE1 -ef FILE2 ]] Same files Example# String if [[ -z "$string" ]]; then echo "String is empty" elif [[ -n "$string" ]]; then echo "String is not empty" else echo "This never happens" fi # Combinations if [[ X && Y ]]; then ... fi ...
-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 STRING is not empty ...
-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 STRING is not empty STRING1 = STRIN2 # True if...
quotes around the variable; that's good, but should be explained. It might be better if it echoed the file name. And this checks that the file exists and is not empty (that's the meaning of-s) whereas the question asks about any file, empty or not (for which-fis more appropriate)...
[[ ... ]] && { command-goes-and-other-things-here; }