Hacker News new | ask | show | jobs
by unwind 4172 days ago
That's normal, but why the trailing slash?! That's just pointless, and almost looks like an explicit deathtrap.

Without the slash, an empty variable would result in a command line of "rf -rf" which would simply fail due to the missing argument.

There is absolutely no need for having a trailing slash, it's not as if "rf -rf foo" and "rm -rf foo/" can ever mean two different things, there can be only one "foo" in the file system after all.

Very interesting way of introducing an epic fail with a single character, that really looks harmless.

3 comments

> it's not as if "rf -rf foo" and "rm -rf foo/" can ever mean two different things

That's true, but the original code was akin "rm -rf foo/*" and that's different, since it removes the content of the directory while preserving it.

I have observed that ,any people feel that directories “need” to have a slash appended to them. They are afraid of ever doing, e.g. “cd /foo/bar” and will always do “cd /foo/bar/”. I”m guessing they feel like it would be some sort of type error, like treating a directory like a file or something.

This behavior is especially common with regards to URLs; there are many flamewars about whether URLs “need” a trailing slash or not.

The trailing /* is to delete the directory _contents_ rather than the dir itself. It would be safer to receate the dir as then you can possibly hit some of the inbuilt rm protections