Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> Unset variables. If DIR is unset, rm -rf $DIR/ becomes rm -rf /. Using set -u can make bash error when encountering unset variable.

sweet mercy :O

Someone call the Inquisition



Instead, say

  rm -rf $DIR
That is, skip the trailing slash. Then if $DIR is not set, it becomes an invalid command, because no file names were supplied.


Better to make the requirement explicit, instead of relying on the argument-parsing details of rm or some other command:

    # Default message
    $ rm -rf "${DIR:?}"
    bash: DIR: parameter null or not set

    # Custom message
    $ rm -rf "${DIR:?It is not set OMG}"
    bash: DIR: It is not set OMG


This was a very famous Steam bug




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: