Bash example

Florent Charton traydent at gmail.com
Fri Aug 21 07:58:15 UTC 2009


Le 21/08/2009 00:42, Chris a écrit :
> Greetings,
>   
Hello,
> I would like an example bash script that checks to see if a directory
> exists. If it does, then remove it.
>   
A solution among others :
rmdir_if_exists() {
    [ $# -eq 1 ] || (echo "Need the directory name" >&2 ; exit 1)
    [ -d "$0" ] && rm -Rfv "$0"
}

Then, just :
rmdir_if_exists /tmp/tmp
A less complicated solution is rm -Rfv /tmp/tmp

-- 
~TraydenT~





More information about the ubuntu-users mailing list