[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: test if shell is interactive
From: |
Bob Proulx |
Subject: |
Re: test if shell is interactive |
Date: |
Sun, 22 Jan 2012 13:42:32 -0700 |
User-agent: |
Mutt/1.5.21 (2010-09-15) |
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)?
I usually check if the standard input file descriptor is attached to a
tty device or not.
#!/bin/sh
if [ -t 0 ]; then
echo has a tty
else
echo does not have a tty
fi
exit 0
Or something like:
$ test -t 0 && echo yes tty || echo no tty
Note: This discussion thread is much better suited for help-bash since
it isn't talking about a bug in bash. In the future if you are just
asking questions that would be the better list to send them to.
Bob