rm misbehavior

Karl Auer kauer at biplane.com.au
Sun Dec 29 23:25:26 UTC 2024


On Sun, 2024-12-29 at 14:25 -0800, MR ZenWiz wrote:
> I (now) know that the function is not quite correct (the parameter
> handling is incorrect). However, if rm is given a list of paths that
> include a directory, shouldn't it refuse to delete the directory
> absent -f or -r?

Yes it should (well, the real /usr/bin/rm should - and does). So the
obvious answer is that either "$RF" or "$*" contains "-r" (or "-R", or
"--recursive") by the time it/they are passed to /usr/bin/rm. Your code
does not check for those.

Of course, the obvious answer is not necessarily correct :-)

A slightly less obvious possibility is that /usr/bin/rm is not what you
think it is. Try "/usr/bin/rm --version".

I tried your code and a cursory test says it doesn't delete a
directory, at least not in the simple case of "rm x" where "x" is a
directory... so I'm mystified too, but only as to how it failed for
you, as it did not fail for me. I suggest adding an output so that you
know when your function has been called - and maybe output "$RF" and
"$* while you are at it.

TBH the purpose of your function is not clear to me. It doesn't seem to
add anything much to the native "rm"...?

If you want more help, I think we need to see *exactly* how you used
your function to delete a directory.

Regards, K.

-- 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Karl Auer (kauer at biplane.com.au, he/him)
http://www.biplane.com.au/kauer






More information about the ubuntu-users mailing list