the test -s for the “if” statement

前端 未结 2 1273
滥情空心
滥情空心 2021-01-27 13:31

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 m

2条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-27 14:22

    -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"
    

    (I have wondered what the rationale for -a is, since I'm not aware that it does anything different from -e.)

提交回复
热议问题