help-bash
[Top][All Lists]
Advanced

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

Re: How can a script know whether it is directly called in a terminal?


From: Greg Wooledge
Subject: Re: How can a script know whether it is directly called in a terminal?
Date: Wed, 25 Mar 2020 08:30:37 -0400
User-agent: Mutt/1.10.1 (2018-07-13)

On Wed, Mar 25, 2020 at 01:54:14PM +0900, Koichi Murase wrote:
> 2020/3/23 2:47 Peng Yu
> > I'd like to know within a script whether it is called directly by
> > someone at the terminal.

I'd ask "why", but....

> I guess you want to test whether the script is directly called by an
> interactive session of shells. If you want to check if the parent
> process is the session leader or not, you can compare PPID with its
> SID. [...]

There's a decent chance that they want something from:

https://mywiki.wooledge.org/BashFAQ/109

It's also possible that they simply want to implement a command that
changes behavior when stdout is a terminal.  In that case, test -t 1
is the thing.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]