Linode Forum
Linode Community Forums
 FAQFAQ    SearchSearch    MembersMembers      Register Register 
 LoginLogin [ Anonymous ] 
Post new topic  Reply to topic
Author Message
PostPosted: Fri Feb 26, 2010 12:52 pm 
Offline
Junior Member

Joined: Wed Sep 03, 2008 9:51 am
Posts: 25
NEVERMIND, THIS DOESN'T WORK!

Some of the functions I wrote up in my StackScripts were so cool, I wanted to use them *after* the machine was installed. However, on a StackScript where there are <ssinclude> tags, it choked up bash.

So, we include the <ssinclude> tag in a quote that escapes the <> chars, then wrap the whole thing in a case statement that detects whether the script is being run from an interactive shell, or from a non-interactive one (first boot as a StackScript invokation):
Code:
case "$-" in
        *i*)
                PATH=$(cd ${0%/*} && pwd -P)
                source "${PATH}/bash_lib_rh.sh"
                source "${PATH}/drupal_lib_rh.sh"
        ;;
        *)
                source '<ssinclude StackScriptID="154">'
                source '<ssinclude StackScriptID="162">'
        ;;
esac


The only thing you have to do after using this code is to make sure you export your UDF variables before you run anything.[/code][/b]


Top
   
 Post subject:
PostPosted: Sat Feb 27, 2010 1:32 am 
Offline
Senior Member
User avatar

Joined: Sun Jan 18, 2009 2:41 pm
Posts: 830
You can use the tty command in a script to test if it's being run in an interactive shell. Just do tty > /dev/null and check the exit status:
Quote:
0
Standard input is a terminal.
1
Standard input is not a terminal.
>1
An error occurred.


Top
   
 Post subject:
PostPosted: Sat Feb 27, 2010 8:57 am 
Offline
Senior Member
User avatar

Joined: Tue Apr 13, 2004 6:54 pm
Posts: 833
Or use the "-t" test
Code:
if [ -t 0 ]
then
  echo STDIN is connected to a terminal
else
  echo No terminal
fi

_________________
Rgds
Stephen
(Linux user since kernel version 0.11)


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
RSS

Powered by phpBB® Forum Software © phpBB Group