在bash 中的if-else 中使用空白的敘述

在bash 中的if-else 中使用空白的敘述

if lsof "$filename" > /dev/null
then
  # file is open
  :
else
  echo "deleting $filename"
  rm "$filename"
fi

在bash 中 “:” 表示空白的敘述.
若沒有”:” 則會出現語法錯誤.

參考來源: Bash syntax error when “else” follows an empty “then” clause

This entry was posted in 程式設計 and tagged , . Bookmark the permalink.

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *