News for hackers. Stuff that matters.
Re:Unix Wildcards Gone Wild by dap on Sunday August 17, 2014 @03:20PM (#8190152)
Good summary of surprising behavior. You can work around a lot of these issues using "--" as an argument before you use any wildcards. This tells most commands to stop processing options and treat the rest of the arguments as files (or whatever other non-option arguments the command takes). That's getopt(3)'s behavior[0]. For example, "rm -- *" will not have the problem where directories are removed if there's an entry called "-rf" in the directory.

[0] http://pubs.opengroup.org/onlinepubs/9699919799/functions/ge...

Re:Unix Wildcards Gone Wild by mikeash on Sunday August 17, 2014 @03:29PM (#8190186)
A better workaround is to prefix your wildcarded arguments with ./ as this will work with all commands. For example, rm ./* will safely remove files regardless of how they're named.