1 Jun 2007 01:10
Re: Checking environment?
On Thu, May 31, 2007 at 01:18:07PM -0600, Ashley M. Kirchner wrote:
> Is there some way to check whether a (bash shell) script is being
> called from the command line or via a web process? I need a way
Not as such, but you can use some tricks to determine if you're being
called from an interactive process on a relatively standard system. For
example:
- shopt login_shell # Is shell a login shell?
- test -n "$PS1" # Is shell interactive?
Keep in mind that this is based on standard behavior, and you can do all
sorts of weird things that make this sort of result unreliable. For
example, starting shells with "bash -i" or unsetting PS1 in your
~/.bashrc file would seriously confuse the issue. So don't do those
things. :)
Most CGI environment variables are server- and request-specific, but the
specification says that they all need to set the server name:
test -n "$SERVER_NAME"
You can also try such variables as DOCUMENT_ROOT (would this ever not be
set?) or some other relevant piece of info you could rely on as being
only set by your web server.
--
--
"Oh, look: rocks!"
-- Doctor Who, "Destiny of the Daleks"
(Continue reading)
RSS Feed