the test -s for the “if” statement

前端 未结 2 1234
滥情空心
滥情空心 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:15

    This if command simply prints the string file is zero sized and not exist | is exist and zero sized | not exist (obviously zero sized) if the file does not exist or if the file is zero sized.

    If you want your if command to check only for the zero sized file and not file existence then you can do something like this :

    if [[ $(du -h "$the_file_to_check" |cut -f 1) == "0" ]] ;then echo "file is zero sized" ; fi

    But this if statement will post a error if file does not exist. Make sure you execute this only when the file is present.

提交回复
热议问题