- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Checking if 'we' are running in an interactive she...
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-31-2006 12:55 AM
07-31-2006 12:55 AM
Just a quick question, I used to have a script floating about that could determin if a shell was interactive or not (ie run by cron etc). Please would some kind soul remind me how it's done?
All pointers / tips / RTFF etc warmly received as ever!
Cheers,
-=ChaZ=-
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-31-2006 01:00 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-31-2006 01:01 AM
07-31-2006 01:01 AM
Re: Checking if 'we' are running in an interactive shell....
if [[ $- = *i* ]]; then
#interactive shell
else
#non-interactive shell
fi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-31-2006 01:02 AM
07-31-2006 01:02 AM
Re: Checking if 'we' are running in an interactive shell....
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-31-2006 02:07 AM
07-31-2006 02:07 AM
Re: Checking if 'we' are running in an interactive shell....
if [ -t 0 ]
then
echo "We are interactive"
else
echo "We ain't no interactive active session nohow"
fi
or better (because the external test command is replaced with the shell's internal test):
if [[ -t 0 ]]
then
echo "We are interactive"
else
echo "We ain't no interactive active session nohow"
fi
-------------------------------
In any event, testing to see if stdin is a tty device is a standard UNIX idiom.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-31-2006 02:12 AM
07-31-2006 02:12 AM
Re: Checking if 'we' are running in an interactive shell....
Cheers!
-=ChaZ=-
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-31-2006 07:51 AM
07-31-2006 07:51 AM
Re: Checking if 'we' are running in an interactive shell....
if tty -s
then
...interactive stuff...
fi
Highly portable among POSIX shells like ksh, HP's sh, bash, etc since an external command is used to determine the interactive status.
Bill Hassell, sysadmin