bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Standard .bashrc needs a minor fix


From: Ken Irving
Subject: Re: Standard .bashrc needs a minor fix
Date: Sat, 8 May 2010 08:42:02 -0800
User-agent: Mutt/1.5.20 (2009-06-14)

On Fri, May 07, 2010 at 03:03:57PM -0400, Mike Frysinger wrote:
> On Friday 07 May 2010 08:49:26 Greg Wooledge wrote:
> > On Thu, May 06, 2010 at 09:30:20AM -0500, Chuck Remes wrote:
> > > e.g.
> > > [ -z "$PS1" ] && return
> > 
> > That's certainly *not* how I'd write that check.  If the goal is to
> > protect a block of commands from running when the shell is invoked
> > without a terminal, then I'd prefer this:
> > 
> > if [ -t 1 ]; then
> >     # All your terminal commands go here
> >     stty kill ^u susp ^z intr ^c
> >     ...
> > fi
> 
> the somewhat common test ive seen in different distros to detect interactive 
> shells is:
> if [[ $- != *i* ]] ; then
>       # shell is non-interactive
>       return
> fi
> -mike

bash(1) (v4.1) includes:

    OPTIONS
        ...
        -i        If the -i option is present, the shell is interactive.

and 

    INVOCATION
        ...
        PS1 is set and $- includes i if bash is interactive,  allowing
        a shell script or a startup file to test this state.
 
The latter statement is ambiguous, possibly suggesting that PS1 should
also be checked to test for an interactive shell.  This is apparently
not the case, judging by this and other responses in this thread.  I'm 
not sure how to reword it, but if testing for i in $- is sufficient then
this might be clarified.

Ken
-- 
Ken.Irving@alaska.edu




reply via email to

[Prev in Thread] Current Thread [Next in Thread]