Obtaining complete Unix command line that evoked script as string



Item: Obtaining complete Unix command line that evoked script as a string

If there is a more appropriate list for this, let me know; the other perl lists I've seen seem to specialised for this.

I'm trying to get the complete command line that invoked a script as a string, that is the output of 'history 1'. Note this is not just the arguments of the call to the script, but everything including pipes and redirects, etc., e.g.

  echo -n "Starting..." ; more some-stuff | \
    doStuff.pl - 3 > save-here.out ; echo "done."

Ideally the perl interpreter would grab the complete command line as its evoked and I'd access this via a variable. As this seem problematic, more realistically, ideally the shell should maintain a "current command" variable in the same fashion as the CWD variable, which can then be exported and read. AFAIK this does exist... (I see at the bottom of the bash FAQ that better environment variable support of perl is on hopeful feature to be added... one day; I'd very much like to see this.)

So... any ideas on something that does work, or am I just plain stuck?

I'm using the bash shell for what its worth. This may appear to be a bash question, but I'm hoping for a perlish solution if possible!


You can achieve this in an ugly unreliable fashion by having the caller set up an environment variable and read this in within the scripts, e.g.


  THISCMD=`history 1` ; doStuff.pl first-time

(and have doStuff read in $THISCMD)

But if the caller doesn't set up the environment variable on any given command line, the previous value is used which is plain wrong. Basically its untrustworthy, defeating my purpose for this, and there doesn't seem to be any particularly easy way to make it trustworthy. In any event, its also plain ugly!
Using bash's PROMPT_COMMAND to clear the value doesn't help, as this doesn't apply if the command lines are within a non-interactive script.



Grant

--
-------------------------------------------------------------------
Grant Jacobs Ph.D.                                     BioinfoTools
ph. +64 3 478 0095  (office, after 10am)               PO Box 6129,
or  +64 27 601 5917 (mobile)                               Dunedin,
gjacobs@xxxxxxxxxxxxxxxx                               NEW ZEALAND.
   Bioinformatics tools: deriving knowledge from biological data
Bioinformatics tools - software development - consulting - training
 15 years experience in bioinformatics ready to solve your problem
Check out the website for more details: http://www.bioinfotools.com

The information contained in this mail message is  confidential and
may be legally privileged.  Readers of this message who are not the
intended recipient are hereby notified that any use, dissemination,
distribution or reproduction of this message is prohibited.  If you
have received this message in error please notify the sender immed-
iately and destroy the original message.  This applies also to  any
attached documents.
.



Relevant Pages

  • Re: [PATCH] Replace scripts/headers_install.pl with a shell script.
    ... Remove perl from make headers_install by replacing a perl script (doing ... Else $i will be evaluated at the time the trap command is used, not at the time we exit, and you need to protect the filenames using "" everywhere. ... "arch is used to force a reinstallation when the arch hanges because kbuild then detect a command line change." ...
    (Linux-Kernel)
  • Re: Displaying a users group memberships
    ... The user's username is passed to the script via the command line and captured with ARGV. ... I want to determine the group memberships (much like executing `groups` from the command line) and run those through a loop for processing. ... I'm very new to Perl so maybe I'm just looking for the wrong terms or something. ... The format of the command is simple: `test.pl username`, where username is a real username on the system in question. ...
    (perl.beginners)
  • Re: "register" (in perl scripts)
    ... scripted gimp. ... This is a Perl problem, not a GIMP problem so you would probably ... it looks to me like you're trying to execute a command ... By the way, your script doesn't appear to use any CGI, etc. - at ...
    (comp.graphics.apps.gimp)
  • Re: Linux
    ... You almost certainly have Perl already installed. ... But the actual command line interpreter should be the same between them. ... put the shebang line as the first line of the script. ... You can then execute the program ...
    (perl.beginners)
  • Re: Problems trying to configure Linux laptop to print to Windows XP shared printer
    ... map to guest = Never ... check password script = ... enumports command = ... ldap delete dn = No ...
    (comp.os.linux.setup)