4 ms·
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 command
by dap 12y ago
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/getopt.html http://pubs.opengroup.org/onlinepubs/9699919799/functions/ge...
- mikeash 12y agoA 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.