LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 01-20-2007, 05:28 AM   #1
anupamsr
Member
 
Registered: Sep 2004
Location: India
Distribution: Kubuntu, Archlinux, Suse, Gentoo, Mandrake
Posts: 370

Rep: Reputation: 30
how to know if the shell is interactive or not?


Hi!

I want to know when the shell is launched interactively and when it is not. I mean, is there some check which I can incorporate in a /etc/profile? Something like this:
Code:
if (interactive shell); then
  echo "it is"
else
  echo "it is not"
fi
 
Old 01-20-2007, 06:37 AM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 27,454
Blog Entries: 54

Rep: Reputation: 2896Reputation: 2896Reputation: 2896Reputation: 2896Reputation: 2896Reputation: 2896Reputation: 2896Reputation: 2896Reputation: 2896Reputation: 2896Reputation: 2896
A bit of RT(Fine)M wouldn't hurt IMNHO.

man bash:
Quote:
An interactive shell is one started without non-option arguments and
without the -c option whose standard input and output are both con-
nected to terminals (as determined by isatty(3)), or one started with
the -i option. PS1 is set and $- includes i if bash is interactive,
allowing a shell script or a startup file to test this state.
man ksh:
Quote:
A shell is interactive if the -i option is used or if both standard
input and standard error are attached to a tty. An interactive shell
has job control enabled (if available), ignores the INT, QUIT and TERM
signals, and prints prompts before reading input (see PS1 and PS2
parameters). For non-interactive shells, the trackall option is on by
default (see set command below).
 
Old 01-20-2007, 07:31 AM   #3
anupamsr
Member
 
Registered: Sep 2004
Location: India
Distribution: Kubuntu, Archlinux, Suse, Gentoo, Mandrake
Posts: 370

Original Poster
Rep: Reputation: 30
Thanks!

I should have looked into man before googling... and google won't accept $ term :P
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
shell script read non-interactive comtmr Linux - General 6 11-01-2006 06:54 AM
interactive and non-interactive shell linuxjamil Programming 3 09-03-2006 08:42 PM
Run interactive program in shell escargot22026 Programming 4 08-14-2004 11:59 PM
[Shell scripting] interactive and crontab pb maxance Programming 4 06-10-2004 12:00 PM
Where is the shell interactive for ruby languaje? Manuel Tejada Red Hat 5 02-02-2004 08:30 PM


All times are GMT -5. The time now is 09:20 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration