by makecheck · 9y ago · 0 comments
— It is possible to “see” a command line (in "ps" output, etc.) in ways that you won’t see environment settings. This can be useful when passing information to a sub-process that you need to keep private.
— It may be that you are configuring your sub-process in a place that is “far away” from the point that actually executes the command. Rather than have to thread an extra command-line argument through your code to make sure it is part of the final command invocation, it can be quite convenient to just set a variable. I have often used this to enable debugging features or test experimental features, or even to disable entire features when unexpected problems arise.
— In a similar way, your program may use multiple languages or otherwise be difficult to manage in any common way without environment variables.
— In a cross-platform scenario, environment variable names might be far easier to keep constant across UNIX, Windows, etc. than command-line syntax.
I’m sure there are other reasons.
One argument for having command-line arguments is that it can be less typing, as argument names can be implied. Compare:
>cp foo bar
with >from=foo to=bar cp
It also seems easier to me to specify multiple arguments from the command line, but that probably could be solved (mostly) by changing sh syntax.