bug-bash
[Top][All Lists]
Advanced

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

Re: test if shell is interactive


From: Chris F.A. Johnson
Subject: Re: test if shell is interactive
Date: Sun, 22 Jan 2012 15:37:54 -0500 (EST)
User-agent: Alpine 2.00 (LMD 1167 2008-08-23)

On Sun, 22 Jan 2012, tapczan wrote:
Bob Proulx wrote:

Shell scripts are not interactive.  So what you are seeing above is
correct.

So, is there any way to test if script (a.sh) was invoked from interactive
session (human) or not (e.g. from cron)?

   Test whether it is attached to a tty:

if [ -t 1 ]
then
   echo Interactive
else
   echo Not interactive
fi

--
   Chris F.A. Johnson, <http://cfajohnson.com/>
   Author:
   Pro Bash Programming: Scripting the GNU/Linux Shell (2009, Apress)
   Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)



reply via email to

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