Ralf Corsepius wrote:
It would be quite easy to provoke: Assume a program to change its behavior depending on whether it's called "X", "Y" or "Z". Now rename it to "A" or try to use copy of X under the name "myX". Which behavior will "A" or "myX" expose? The results will be random.
Not necessarily. It would depend on how the program was coded. Sorry, you're going to have to come up with a more practical example before I'm convinced. I do agree with you though that argv[0] is not under the programmer's control and so it should be treated defensively, just as any other external input should be. I suppose that could be the intent behind the word "depend" in the guideline. If you read it like a lawyer, it only says that the program should not /depend/ on the name to decide the behavior. Does that mean "not depend at all" or "not depend solely" on the name? You could meet the letter of the guideline if the program used its name as /one way/ to adjust it's behavior, but not the /only/ way. These positive guidelines: * The program should have a defined behavior if argv[0] has an unexpected value, * All of the program's behaviors should be accessible by options, and * The options have precedence over argv[0], are consistent with the negative guideline, without killing the whole concept.
IMO, the fact you haven't seen such effects only is the result of only very few programs applying "change behavior upon program name" ;)
I'm no systems whiz, but I've used the technique myself on a number of occasions and found it handy. I'm going to need something substantial before I abandon a useful technique. GNU is probably worried about some larger issues that I don't care so much about. Here's one possibility: writing a program to run across systems that may do some ugly name munging with executables, like, oh, calling it "test.exe" or something. Are there any primitive systems like that still around? <Joe