FS#20717 - [bash] ~/.bashrc can't know when bash is in interactive mode

Attached to Project: Arch Linux
Opened by maxi jac (maxi_jac) - Thursday, 02 September 2010, 08:51 GMT
Last edited by Allan McRae (Allan) - Wednesday, 02 February 2011, 05:30 GMT
Task Type Bug Report
Category Packages: Core
Status Closed
Assigned To Aaron Griffin (phrakture)
Allan McRae (Allan)
Architecture All
Severity Low
Priority Normal
Reported Version
Due in Version Undecided
Due Date Undecided
Percent Complete 100%
Votes 0
Private No

Details

Hi,

Description:
~/.bash_profile sources ~/.bashrc.
bashrc then tries to see when bash is in interactive session by using :

# Check for an interactive session
[ -z "$PS1" ] && return

But it does not work because in both interactive and login bash shells, /etc/profile reads (indirectly) /etc/bash.bashrc that sets the PS1 variable.

In both ways, PS1 is then set.

I don't know if it really matters but I wanted to let you know about that.
Maybe the way ~/.bashrc finds out if it's an interactive shell should be changed.
This task depends upon

Closed by  Allan McRae (Allan)
Wednesday, 02 February 2011, 05:30 GMT
Reason for closing:  Works for me
Comment by Alexander Haeussler (eminor) - Friday, 03 September 2010, 09:39 GMT
I cannot reproduce this here. I created a script

#!/bin/bash
echo "PS1: $PS1"
[ -z "$PS1" ] && echo "not interactive"

and output is:

PS1:
not interactive

If I run [ -z "$PS1" ] && echo "not interactive" in a terminal, there is no output. So I think the test works fine.
Comment by maxi jac (maxi_jac) - Tuesday, 07 September 2010, 08:30 GMT
Hmmm here's what I did, maybe I'm wrong :
in .bashrc I added :

# Check for an interactive session
[ -z "$PS1" ] && return
echo "interactive"

$ bash -l
interactive
$ bash -i
interactive

What do you think of this test case ?
Comment by Paul Bredbury (brebs) - Monday, 13 September 2010, 15:23 GMT
You can check with: $- != *i*

See https://bbs.archlinux.org/viewtopic.php?id=45038
Comment by Allan McRae (Allan) - Wednesday, 02 February 2011, 05:30 GMT
> $ bash -l
> interactive

Isn't this expected... A login shell is not necessarily non-interactive. Test using a script.

Loading...