Unix Shell - Can I find the value of -c "string" in ksh?

This is Interesting: Free IT Magazines  
Home > Archive > Unix Shell > April 2005 > Can I find the value of -c "string" in ksh?





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Can I find the value of -c "string" in ksh?
Paul D. Smith

2005-04-26, 5:56 pm

In ksh, I want to find the value of the command string used by someone
invoking the shell with the -c argument.


For example, just suppose someone invoked my shell like this:

/bin/ksh -l -c "echo hi"

Now, in my ~/.profile (which is read because of the -l option) I'd like
to find out what the command script given to the -c argument was (here,
"echo hi").

I've already tried "$@" and reading stdin; no joy. The shell must stash
that away somewhere else before it starts to run my ~/.profile. Can I
get this information back out?


Please don't tell me how to do it in bash or zsh, or that I should
switch shells, etc.: I need it in ksh, and there's nothing I can do
about it for now.

Thanks!

--
-------------------------------------------------------------------------------
Paul D. Smith <psmith@nortel.com> HASMAT--HA Software Mthds & Tools
"Please remain calm...I may be mad, but I am a professional." --Mad Scientist
-------------------------------------------------------------------------------
These are my opinions---Nortel Networks takes no responsibility for them.
Chris F.A. Johnson

2005-04-26, 8:47 pm

On Tue, 26 Apr 2005 at 22:40 GMT, Paul D. Smith wrote:
> In ksh, I want to find the value of the command string used by someone
> invoking the shell with the -c argument.
>
>
> For example, just suppose someone invoked my shell like this:
>
> /bin/ksh -l -c "echo hi"
>
> Now, in my ~/.profile (which is read because of the -l option) I'd like
> to find out what the command script given to the -c argument was (here,
> "echo hi").
>
> I've already tried "$@" and reading stdin; no joy. The shell must stash
> that away somewhere else before it starts to run my ~/.profile. Can I
> get this information back out?


ps $$

GNU ps:

ps hocommand $$

--
Chris F.A. Johnson <http://cfaj.freeshell.org>
========================================
==========================
Shell Scripting Recipes: A Problem-Solution Approach, 2005, Apress
<http://www.torfree.net/~chris/books/ssr.html>
Paul D. Smith

2005-04-27, 2:48 am

%% "Chris F.A. Johnson" <cfajohnson@gmail.com> writes:

cfaj> On Tue, 26 Apr 2005 at 22:40 GMT, Paul D. Smith wrote:[vbcol=seagreen]

cfaj> ps $$

cfaj> GNU ps:

cfaj> ps hocommand $$

Mmm. ps. One of the LEAST portable UNIX commands ever written :-/.

OK, I can work with that, I guess, if there's no way to get that string
directly. Thanks.

--
-------------------------------------------------------------------------------
Paul D. Smith <psmith@nortel.com> HASMAT--HA Software Mthds & Tools
"Please remain calm...I may be mad, but I am a professional." --Mad Scientist
-------------------------------------------------------------------------------
These are my opinions---Nortel Networks takes no responsibility for them.
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com