[comp.unix.programmer] Getting the original command-line

brad@SSD.CSD.HARRIS.COM (Brad Appleton) (12/07/90)

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 ..)

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

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.

advTHANXance
______________________ "And miles to go before I sleep." ______________________
 Brad Appleton           brad@ssd.csd.harris.com       Harris Computer Systems
                             uunet!hcx1!brad           Fort Lauderdale, FL USA
~~~~~~~~~~~~~~~~~~~~ Disclaimer: I said it, not my company! ~~~~~~~~~~~~~~~~~~~

jik@athena.mit.edu (Jonathan I. Kamens) (12/11/90)

In article <1699@travis.csd.harris.com>, brad@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@Athena.MIT.EDU				Allston, MA  02134
Office: 617-253-8085			      Home: 617-782-0710

md@sco.COM (Michael Davidson) (12/20/90)

In article <1699@travis.csd.harris.com> brad@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? 
 [ ... ]
>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.

Sorry, the short answer to your question is "No". The contents of argv[]
*are* the original arguments to the program when it was exec()-ed (unless
the program itself has subsequently changed them, of course). There is no
way that you can get at the original characters that were typed at the
shell command prompt to cause the program to be run (if indeed it was run
from the shell at all ...)

I am also really puzzled by your statement that you want the original
command line "before quotes and slashes are evaluated but after filenames,
aliases and variables have been expanded" - since in all the shells that
I am familiar with backslash and quote characters play a vital role
in determining just exactly how the command line is interpreted and
what filename expansion etc takes place ....

It might help if you explained exactly what you think that you are
trying to achieve.