A Unix annoyance

January 26, 2006

Unix: where you have to escape command line arguments twice, once from the shell and once from the program.

I dearly love Unix, but I am forced to admit that every so often it has what I can only describe as 'robot logic'; things that are perfectly logical, but not to normal humans. For example, consider the fun of trying to remove a file called something like "-Brad Foo".

$ rm -Brad Foo
rm: invalid option -- B
$ rm "-Brad Foo"
rm: invalid option -- B
$ rm ./-Brad Foo
rm: cannot remove `./-Brad': No such file or directory
rm: cannot remove `Foo': No such file or directory

(and so on.)

Of course this is happening because the arguments are processed twice; once by the shell to determine what's a single argument and what gets split up, and then again by rm itself to find its options. So you have to escape the filename in the shell because it has a space in it, and that's entirely separate from how rm normally thinks anything starting with a dash is a switch, not a filename to be removed. (And programs can be wildly inconsistent in how to escape their arguments.)

I've used Unix sufficiently long and deeply that that I can see and explain all of this in my sleep. It all makes perfect sense and it's completely consistent and logical (once you understand Unix's logic).

But let's be honest here: it's robot logic, not human logic.

(This entry is inspired by the travails of a perfectly technically adept Unix person in a similar situation, as recounted here. He had a simpler example that didn't need being escaped from the shell, just from rm.)

Written on 26 January 2006.
« Site navigation stuff goes on the right side
Pointer: The Unix-Haters Handbook »

Page tools: View Source, Add Comment.
Search:
Login: Password:
Atom Syndication: Recent Comments.

Last modified: Thu Jan 26 02:10:24 2006
This dinky wiki is brought to you by the Insane Hackers Guild, Python sub-branch.