Checking for interactive shell sessions [Was: Re: Can't enter passphrase in su session.]
roam at ringlet.net
Thu May 21 23:04:23 CEST 2009
On Thu, May 21, 2009 at 01:19:44PM -0400, Steven W. Orr wrote:
> The proper way to deal with this is to:
> * Source in your .bashrc from your .bash_profile
> * Set all of your environment variables in your .bash_profile
> * Check in your .bashrc to see if PS1 is set. If not then you are not in
> an interactive session and you need to set critical environment variables.
Just BTW, a *much* more reliable way to check for an interactive
session, which will not fail in many common cases (PS1 set in system-wide
config files, PS1 also set in .bashrc, PS1 set in the environment of
the calling shell, etc.), is the following:
# First, set up all variables for both interactive and non-interactive
# Then, do this:
case "$-" in
echo 'Setting up interactive shell params..'
stty erase ^H
# Non-interactive session, better don't output anything
Of course, substitute your own commands for the "stty" and the assignment :)
Bear in mind that this only applies to Bourne-style shells;
for tcsh, you might need to resort to testing for ($?prompt), indeed.
Peter Pentchev roam at ringlet.net roam at space.bg roam at FreeBSD.org
PGP key: http://people.FreeBSD.org/~roam/roam.key.asc
Key fingerprint FDBA FD79 C26F 3C51 C95E DF9E ED18 B68D 1619 4553
What would this sentence be like if pi were 3?
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Size: 196 bytes
Desc: not available
More information about the Gnupg-users