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