对于"if"的测试-s.陈述 [英] the test -s for the "if" statement
问题描述
我有一个问题,如果有人知道我的回答,我将不胜感激.好的,到这一点.在我的一个脚本中,我有以下表达式,对于表单手册页来说,尚不清楚它应该产生什么效果:
I have a question and i would be grateful for the answer if somebody knows one. Ok, to the point. In one of my scripts i have following expression, it is not clear for me form man page what effect it should produce:
如果![[-s"$ the_file_to_check"]];然后回显文件大小为零且不存在|存在且大小为零|不为零大小且不存在|不为零大小或不存在|不存在(显然为零大小)";fi
存在单独的存在性检查(-a键),为什么还要添加另一个检查?
there exist separate check for existence (the -a key), why to add another one?
以及这种逻辑如何工作.
And how this logics works in anyway.
我的定义有些失落.
P.S.
我需要检查是否为空,但不存在.谢谢大家.
P.S.
I need a check for emptiness but not existence. Thank everyone.
推荐答案
-s
不仅检查文件是否存在,还检查文件是否包含任何数据(即文件是否大小)大于0个字节).这比 -a
选项(实际上是 -e
的同义词)所做的更多,后者仅测试文件是否存在.
-s
checks not only if the file exists, but also if it contains any data (that is, if it has a size greater than 0 bytes). This is more than the -a
option (which is, in fact, a synonym of -e
) does, which only tests if the file exists.
touch foo
[[ -a foo ]] && echo "File foo exists"
[[ -s foo ]] || echo "File foo exists, but is size 0 bytes"
(我想知道 -a
的原理是什么,因为我不知道它的作用与 -e
有所不同.)
(I have wondered what the rationale for -a
is, since I'm not aware that it does anything different from -e
.)
这篇关于对于"if"的测试-s.陈述的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!