Bash example

Johnny Rosenberg gurus.knugum at gmail.com
Fri Aug 21 09:56:21 UTC 2009


2009/8/21 Florent Charton <traydent at gmail.com>:
> 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~
>
>
> --
> ubuntu-users mailing list
> ubuntu-users at lists.ubuntu.com
> Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
>

I just don't understand why you need to check if the directory exists.
If it doesn't, remove it anyway. That won't hurt anybody. Just set the
right option to the rm command, so it doesn't give you an annoying
error.

Johnny Rosenberg




More information about the ubuntu-users mailing list