Re: Korn shell question

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

 





On Tue, Apr 15, 2008 at 5:51 PM, Patrick O'Callaghan <pocallaghan@xxxxxxxxx> wrote:

On Tue, 2008-04-15 at 16:56 -0700, Don Russell wrote:
>
>
> On Tue, Apr 15, 2008 at 4:17 PM, Cameron Simpson <cs@xxxxxxxxxx>
> wrote:
>
>         On 15Apr2008 12:09, Don Russell <fedora@xxxxxxxxxxxxxxxxxxxxx>
>         wrote:
>         | On Tue, Apr 15, 2008 at 11:08 AM, Patrick O'Callaghan
>         <pocallaghan@xxxxxxxxx>
>         | 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
>         | > and work from there.
>         |
>         | That looks promising... thanks :-)
>
>
>         Promising, but will work only on Linux. That may be enough for
>         you, but you
>         shouldn't forget that it's nonportable.
>
> I just tried this on a Linux system... it makes sense... I tried it on
> a UNIX (AIX) system, and it did not help directly. On UNIX the status
> file appears to be "raw" binary data that maps to a C structure...
> could get tricky trying to extract the correct parts.

I'm amazed it even exists on AIX. I was assuming you meant Linux (this
is a Fedora list after all).

Yes, and some of the most Unix/Linux knowledgeable people I know. :-)
 

> On Linux, it looks like that decoding is all done and present in
> human-readable terms. :-)
>
>
>
>
>         You can probably make that `cat|grep|cut` into a single `sed`
>         at some
>         performance benefit.
>
>         Another approach is to alter your shell environment to always
>         set and export
>         an environment variable when starting vi (by invoking vi via a
>         wrapper script
>         or alias or shell function) and then just checking for it.
>
> Though simple, that's not an option for me.... I can't "wrap" vi...

You can. Just put the wrapper in $HOME/bin and set PATH=$HOME/bin:$PATH, e.g.

$ cat $HOME/vi
#!/bin/sh

export MY-SPECIAL-FLAG=1
exec /usr/bin/vi $*
$


Well, yes, I can do it for me, but I'm not in a position to do it for all the other users of the system to which I do not have root access. I *do* have control over the script they all use, which is why I want to detect "in a sub-shell" from that script, then I can just exit with an error message...

You've given me some good information... I just might have to decode the raw binary data on AIX instead of having the friendly text as seen on Linux. :-)

In the mean time, if people complain that it fails when run from a sub-shell, I just reply with "don't run it from a sub-shell". :-)

And maybe before too long, the whole point will be moot because the part that breaks right now will be replaced...
Still, a fun exercise. :-)

Cheers

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

  Powered by Linux