Where am I (csh)

Michael O'Donnell mod+gnhlug at std.com
Wed Jan 15 16:23:26 EST 2003


The short answer is: it can't be done, at least not
in any manner that won't cause projectile vomiting,
so just remember that you asked...

A hack like this might start with the understanding
that "scripts" are not, in themselves, executable.
What's really happening when you "execute" a script is
that the appropriate program (like bash or perl or tcl
or whatever) is secretly launched and the script is
fed to it for interpretation.  That, in turn, usually
means that (at least) one of that interpreter's file
descriptors will refer to the "file" that the script
is coming from.  So, if you're truly twisted you might
rummage around in /proc/pidOfInterest/fd/ and see what
you can find.  For example, I note that descriptor 255
seems to refer to the script in question on my 2.4.18
Debian system when I'm "executing" bash scripts.

 [ Note that pidOfInterest will be that of the
   interpreter (csh in your case) that's executing
   your script, typically available as $$          ]

Of course, there's a whole lot a ways this approach
can fail - one (of many) that immediately comes to
mind is if the script is being piped to you as stdin
from another process.

For the record: trickery like this is ugly, guaranteed
to be non-portable and causes cancer - you should be
forced to swim 50 laps in a septic tank if you ever
attempt to put a hack like this into service.




More information about the gnhlug-discuss mailing list