Re: Korn shell question

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Don Russell wrote:
On Wed, Apr 16, 2008 at 10:37 AM, Don Russell
<fedora@xxxxxxxxxxxxxxxxxxxxx> wrote:





On Wed, Apr 16, 2008 at 8:44 AM, Patrick O'Callaghan <pocallaghan@xxxxxxxxx> wrote:


On Wed, 2008-04-16 at 10:41 -0400, Bill Davidsen wrote:
Patrick O'Callaghan wrote:
On Tue, 2008-04-15 at 10:49 -0700, Don Russell wrote:
How can I tell, from a Korn shell script, if the script is running in
a vi sub-shell?

I have a script that has a problem when run from a vi subshell, and
I'd like to check for that condition and just issue an error message.
(I know that's not the solution to the problem, but the thing that
fails is being replaced, so this is a temporary "fix")
Try:

ls -l /proc/`cat /proc/$$/status|grep PPid|cut -f2`/exe
What on Earth are you doing here?
1) unless you have some reason to doubt the value of $PPID, you are just
    making this look complex
2) if this is a login shell, you will not have permission to read the
    exe symbolic link.
3) you probably just want to see if /proc/$PPIC/cmdline matches vi
Duh, yes. The OP wants to know if his script is being executed from
'vi'. That's one way to do it. You're right about the permissions of
course, my bad, but using $PPID doesn't change that in the script.

Here's a better one:

ps -p $PPID -o comm=


That's GREAT! It's exactly what I need.... and bonus points for it working on other platforms too ;-)

I spoke too soon... I had to tweak it a little.... since running the
script starts a new shell, it's not enough to look at the parent... I
have to go back a generation further to look at the Grand Parent
PID...

Thus, in the script that cares about such things...

GPPID=`/usr/bin/ps -p $PPID -oppid=`
if [[ "LOGINSHELL" != `/usr/bin/ps -p $GPPID -o comm=` ]]; then
     print "$0 not allowed from sub-shell" >&2
     exit 1
fi

Of course the LOGINSHELL literal could be system specific...

Sounds like a job for $SHLVL

--
Bill Davidsen <davidsen@xxxxxxx>
  "We have more to fear from the bungling of the incompetent than from
the machinations of the wicked."  - from Slashdot

--
fedora-list mailing list
fedora-list@xxxxxxxxxx
To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list

[Index of Archives]     [Current Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]     [Fedora Docs]

  Powered by Linux