Finding out if you're inside "script"

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


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.  To use SHLVL you'd have to start laying breadcrumbs,
and that would be very tricky ...  It's useful though because a
colourized prompt is particularly ugly in the typescript - there are
ways around that, but better to have a plain text prompt.

This might work:

  if [ "$(ps -Ao pid,comm | grep $PPID | awk '{print $2}')" = "script" ]
  then
    # Change prompt appropriately
  fi

Would this be a reliable way to determine if the shell was the child
of a "script" command?

-- 
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