Getting the original command-line

Jonathan I. Kamens jik at athena.mit.edu
Tue Dec 11 06:46:45 AEST 1990


In article <1699 at travis.csd.harris.com>, brad at SSD.CSD.HARRIS.COM (Brad Appleton) writes:
|> Is there a way in Unix (BSD and/or AT&T) to retrieve the original command-line
|> in a C program? If so, what state will it be in? (Will variables and aliases
|> be expanded, what about quotes and backslashes, etc ..)

  No.

|> Also - does the shell being used make a difference in how the command-line is
|> retrieved?

  The shell makes all the difference in the world, since the shell is the only
thing that knows the command line that the user actually typed.  On the other
hand, the shell makes no difference at all, since none of the shells that I
know of provide any mechanism at all to do what you describe.

|> BTW - I really do NOT want argv in this particular case. I want the orignal
|> command-line, hopefully before quotes and slashes are evaluated but after
|> filenames, aliases, and variables have been expanded.

  There's a good chance that by the time your program starts up, the shell
doesn't even know what command line it used to start it.  Even if it does
know, that knowledge is completely internal to the shell, and I doubt very
much you're going to be able to figure out a feasible way to drag it out of
the shell.

  The closest you could get would be to define a shell script or something
that passes its arguments into the program or that writes them to a file for
the program to read or something, but since the arguments it gets will have
already been interpreted by the shell, all of the evaluations and expansions
you mention will already have taken place.

  Why exactly are you trying to accomplish this?

-- 
Jonathan Kamens			              USnail:
MIT Project Athena				11 Ashford Terrace
jik at Athena.MIT.EDU				Allston, MA  02134
Office: 617-253-8085			      Home: 617-782-0710



More information about the Comp.unix.programmer mailing list