 |
Linode Forum Linode Community Forums
|
| Author |
Message |
justintime
Joined: 03 Sep 2008
Posts: 25
|
| Posted: Fri Feb 26, 2010 11:52 am Post subject: Stupid Bash Trick: Make StackScripts work from a shell |
|
|
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] |
|
| Back to top |
|
Vance
Joined: 18 Jan 2009
Posts: 350
|
| Posted: Sat Feb 27, 2010 12:32 am Post subject: |
|
|
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. |
|
| Back to top |
|
sweh
Joined: 13 Apr 2004
Posts: 565
|
| Posted: Sat Feb 27, 2010 7:57 am Post subject: |
|
|
Or use the "-t" test
Code:
if [ -t 0 ]
then
echo STDIN is connected to a terminal
else
echo No terminal
fi |
|
| Back to top |
|
| |
|