rm misbehavior

MR ZenWiz mrzenwiz at gmail.com
Mon Dec 30 18:48:30 UTC 2024


On Sun, Dec 29, 2024 at 5:57 PM Karl Auer <kauer at biplane.com.au> wrote:
>
> On Sun, 2024-12-29 at 16:48 -0800, MR ZenWiz wrote:
> > I modified the function to work "properly"
>
> How? What does the fixed function look like?
>
Thanks for asking. I settled on this:

rm ()
{
    typeset RF;
    typeset ln="no";
    [[ "$1" == "-x" ]] && shift && set -x; ### so I can debug this as needed
    for i in $*; do
        case $i in
            -*[Rr]*)  RF="$RF $i";;
        esac;
        if [[ -d $i && -n "$RF" ]]; then
            [[ "$i" == "/" ]] && echo "Deleting the root dir is not
allowed" && set +x && return 1;
            read -p "Are you SURE??? " ln;
            [[ "$ln" != "yes" ]] && set +x && return 1;
            break;
        fi;
    done;
    command rm -I -v --one-file-system --preserve-root=all $*;
    typeset err=$?;
    set +x;
    return $err
}

Note: this is for my user only - does not touch anything for root.

Thanks for all the input.

MRZ




More information about the ubuntu-users mailing list