How to run shell script in silent mode | Unix Linux Forums | UNIX for Dummies Questions & Answers

  Go Back    


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

How to run shell script in silent mode

UNIX for Dummies Questions & Answers


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 12-03-2005
x057373 x057373 is offline
Registered User
 
Join Date: Dec 2005
Last Activity: 6 July 2006, 1:58 PM EDT
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
How to run shell script in silent mode

Hi,

I have a AIX shell script that normally runs in an interactive mode. Now there is a need to it in silent mode and take all default answers.

How do I do that?

Thanks.
Sponsored Links
    #2  
Old 12-04-2005
grahamb grahamb is offline
Registered User
 
Join Date: Dec 2005
Last Activity: 27 July 2008, 5:17 PM EDT
Location: Windsor, Ont Canada
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Running sliently - not interactively

Hi!

Try this idea;

If a script needs to test whether it is running in an interactive shell, it is simply a matter of finding whether the prompt variable, $PS1 is set. (If the user is being prompted for input, then the script needs to display a prompt.)

Code:
if [ -z $PS1 ] # what no prompt?
then
  # non-interactive;   ...
else
  # interactive;   ...
fi

There are other ideas there in this link: http://www.tldp.org/LDP/abs/html/intandnonint.html

One more is that if in background/foreground there is a tty-variable that is set or not set. You could also do something like put a special variable in "~./.profile" that shows that the user is online, eg: $PS1 above. (Just ideas: got no references or clearer ideas on these last ones!)

Hope that was helpful
GrahamB
Sponsored Links
    #3  
Old 12-04-2005
bakunin bakunin is offline Forum Staff  
Bughunter Extraordinaire
 
Join Date: May 2005
Last Activity: 29 July 2014, 4:24 AM EDT
Location: In the leftmost byte of /dev/kmem
Posts: 4,124
Thanks: 43
Thanked 770 Times in 606 Posts
A Korn shell in interactive mode has the "-i" flag set, hence:


Code:
if [ $(print - "$-" | grep -c "i") -gt 0 ] ; then
     print - "shell is interactive"
else
     print - "shell is non-interactive"
fi

bakunin

Last edited by bakunin; 12-04-2005 at 08:00 PM..
    #4  
Old 12-04-2005
zazzybob's Avatar
zazzybob zazzybob is offline Forum Advisor  
Registered Geek
 
Join Date: Dec 2003
Last Activity: 13 May 2013, 9:02 AM EDT
Location: Melbourne, Australia
Posts: 2,185
Thanks: 3
Thanked 24 Times in 23 Posts
My two cents....


Code:
case $- in
   *i*) echo "Yay" ;;
   *  ) echo "Nay" ;;
esac

Cheers
ZB
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Run a script in silent mode firestar Shell Programming and Scripting 4 08-12-2010 01:46 PM
identifying SU mode by shell script Turtel Red Hat 2 03-15-2010 05:49 AM
Vi Mode of Shell Not Starting almond UNIX for Advanced & Expert Users 4 06-22-2009 04:58 AM
Wine in silent mode myle Linux 1 03-10-2008 07:53 AM
silent telnet cgardiner UNIX for Dummies Questions & Answers 1 09-16-2001 10:31 AM



All times are GMT -4. The time now is 06:43 AM.