Finding out if you're inside "script"

Giles Orr gilesorr-Re5JQEeQqe8AvxtiuMwx3w at public.gmane.org
Tue May 22 21:40:13 UTC 2007


On 5/22/07, Chris F.A. Johnson <cfaj-uVmiyxGBW52XDw4h08c5KA at public.gmane.org> wrote:
> On Mon, 21 May 2007, Giles Orr wrote:
> > I'm looking at updating the "Bash Prompt HOWTO," and one thing that's
> > frustrated me is the ability to detect whether or not you're inside a
> > "script" shell.  Being able to determine if you're inside "screen" is
> > useful, particularly if you don't use a status bar, because you can
> > have the prompt modify itself if it detects either TERM=screen or
> > STY={something}.  Fairly easy because "screen" changes the
> > environment.  But inside "script" the only settings that change are
> > SHLVL and PPID. [SNIP]

> case $(ps -ocomm= "$PPID") in
>          script) echo Inside script ;;
>          *) echo Not a \"script\" shell ;;
> esac

Thanks everyone who replied to this, all the suggestions are helpful.
The "case" suggestion above is probably what I'll try in prompt(s), as
it will allow for detection of "script," "screen," "bash" (ie.
multiple shell levels, although there are other ways to find that),
and other possible parents as well.

As for people who have multiple levels of subshells with "script" as a
parent as someone suggested ...  At that point you're doing something
fairly complex and either you know exactly what you're doing or you're
very, very confused - either way, I don't think a specialised prompt
will help you.  :-)  The detection routine for that situation would
probably be too complex to be worth it.

-- 
Giles
http://www.gilesorr.com/
gilesorr-Re5JQEeQqe8AvxtiuMwx3w at public.gmane.org
--
The Toronto Linux Users Group.      Meetings: http://gtalug.org/
TLUG requests: Linux topics, No HTML, wrap text below 80 columns
How to UNSUBSCRIBE: http://gtalug.org/wiki/Mailing_lists





More information about the Legacy mailing list