Is there a way to check if the supplied path either by user input or some self-detect-mechanism safe to be deleted in bash scripting?
rm -rf $SOMELOCATION
No; you need to check the value of
SOMELOCATION before you use it as the argument to
case $SOMELOCATION of /|/var|/etc|/home|/usr|/opt|/root) echo "Will not delete $SOMELOCATION" ;; *) rm -rf "$SOMELOCATION ;; esac
rm to fail, but since
root essentially has permission to do anything, it is simply up to you to take appropriate care when running any command as
root. (Or at the very least, to have an up-to-date backup available to recover from a mistake.)