Arch Linux

Please read this before reporting a bug:
https://wiki.archlinux.org/title/Bug_reporting_guidelines

Do NOT report bugs when a package is just outdated, or it is in the AUR. Use the 'flag out of date' link on the package page, or the Mailing List.

REPEAT: Do NOT report bugs for outdated packages!
Tasklist

FS#22885 - [bash] PROMPT_COMMAND only available in X

Attached to Project: Arch Linux
Opened by orbisvicis (orbisvicis) - Monday, 14 February 2011, 07:04 GMT
Last edited by Allan McRae (Allan) - Tuesday, 15 February 2011, 20:43 GMT
Task Type Bug Report
Category Packages: Core
Status Closed
Assigned To 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

Description:
$PROMPT_COMMAND is only available in X. Not after /bin/login.

Could this have to do the new /etc/bash.bashrc. I'm not sure about old behaviour, I was just testing new changes. I notice lack of "export".


Additional info:
* package version(s)
core/bash 4.1.009-4
This task depends upon

Closed by  Allan McRae (Allan)
Tuesday, 15 February 2011, 20:43 GMT
Reason for closing:  Not a bug
Additional comments about closing:  See comments
Comment by Eric Belanger (Snowman) - Tuesday, 15 February 2011, 03:20 GMT
According to /etc/bash.bashrc, it's expected behavior. PROMPT_COMMAND is only exported in non-login shell.

BTW, the echo command used to define PROMPT_COMMAND doesn't work here (bash 4.2). It prints nothing so PROMPT_COMMAND doesn't get defined at all.
Comment by orbisvicis (orbisvicis) - Tuesday, 15 February 2011, 07:13 GMT
I'm a bit confused.

[console]: bin/login -> bash (login,interactive) ($PROMPT_COMMAND undefined) -> bash (non-login, interactive) ($PROMPT_COMMAND undefined)
[X]: xterm (non-login,interactive). $PROMPT_COMMAND defined.
(all cases verified by running 'echo "${-}"')

Also, as far as I know:
login shell -> (systemwide bash_profile --sources--> systemwide bashrc) -> (local bash_profile --sources--> local bashrc)
Arch:
non-login shell -> local bashrc
Debian/Ubuntu (patched)
non-login shell -> systemwide bashrc -> local bashrc

So the systemwide bashrc should get sourced/executed only in all interactive login shells. An interactive shell is any shell not started with the argument "-c". Therefore /etc/bash.bashrc will be fully sourced directly from /bin/login.

According to the the package repository for bash 4.2, /etc/bash.bashrc neither exports any variables nor uses the "echo" command ("printf" instead). Bash 4.2 and my version (4.1.009-4) share the same bash.bashrc.

Note about $PROMPT_COMMAND:
PROMPT_COMMAND gets executed before PS1.
As already mentioned, under X $PROMPT_COMMAND gets defined to:
$ echo $PROMPT_COMMAND
printf "\033]0;%s@%s:%s\007" "${USER}" "${HOSTNAME%%.*}" "${PWD/#$HOME/~}"
$
while under the console:
$ echo $PROMPT_COMMAND

$
The $PROMPT_COMMAND actually sets the "icon name" and "bar title" before each and every command. Change directory and watch the window title change.

Some other notes:

Since bash.bashrc is only sourced by the login shell (from /etc/profile) which is by definition interactive I think, the following two lines are unnecessary:
# If not running interactively, don't do anything
[[ $- != *i* ]] && return
(Especially since /etc/profile also tests for an interactive shell - 'if test "$PS1"')

Since bash.bashrc is only sourced by the login shell and the variables PS[1-4] and PROMPT_COMMAND are not exported, these variables should only be available to the current process (the login shell) and not any child processes. Therefore, it might be more suitable to actually export them.
- I can't explain while child processes actually seem to inherit them.

Since PROMPT_COMMAND is only evaluated once, perhaps it should be more dynamic:
prompt_command () {
case ${TERM} in
xterm*|rxvt*|Eterm|aterm|kterm|gnome*)
echo 'printf "\033]0;%s@%s:%s\007" "${USER}" "${HOSTNAME%%.*}" "${PWD/#$HOME/~}"'

;;
screen)
echo 'printf "\033_%s@%s:%s\033\\" "${USER}" "${HOSTNAME%%.*}" "${PWD/#$HOME/~}"'
;;
esac
}
PROMPT_COMMAND=prompt_command

I think my original bug report needs to be more specific:
1]
Bash defaults (from man bash):
PS1='\s-\v\$ '
PS2='>'
PS3='>'
PS4='+'
PROMPT_COMMAND=''
From console:
PS1='[\u@\h \W]\$'
PS2='>'
PS3='>'
PS4='+'
PROMPT_COMMAND=''
* From this I conclude that either the bash defaults are wrong, or the environment variables from bash.bashrc where successfully set, and for some reason the console has problems 'echo "$PROMPT_COMMAND"'
From X:
PS1='[\u@\h \W]\$'
PS2='>'
PS3='>'
PS4='+'
PROMPT_COMMAND='printf "\033]0;%s@%s:%s\007" "${USER}" "${HOSTNAME%%.*}" "${PWD/#$HOME/~}"'
2] Since /etc/bash.bashrc is only run once from the login shell, how come child process in X seem to inherit PS[1-4] and PROMPT_COMMAND, especially since these variables were not exported. In any case shouldn't they be exported.
Comment by Eric Belanger (Snowman) - Tuesday, 15 February 2011, 07:33 GMT
I just realized that I forgot to merge /etc/bash.bashrc.pacnew. Sorry about that.
Comment by Allan McRae (Allan) - Tuesday, 15 February 2011, 07:59 GMT
Does your $TERM does not match any of those in the case statement when using the console? I guess not... which would explain why this is not set. And given your console does not have a title bar for that addition to the $PROMPT_COMMAND, I'd say that is expected behaviour.

Also, "export" is clearly not needed as is shown by your PS1 etc being set to the values in /etc/bash.bashrc.

Finally, the interactive bash checks should be removed /etc/profile, not /etc/bash.bashrc as /etc/bash.bashrc is still sourced when /etc/profile is not (non-login shell).
Comment by Jan de Groot (JGC) - Tuesday, 15 February 2011, 10:23 GMT
We use PROMPT_COMMAND to set terminal titles. This is only needed for X terminals or screen sessions, which is why we don't define them outside of these.
Comment by orbisvicis (orbisvicis) - Tuesday, 15 February 2011, 13:22 GMT
Thanks, I understand. I guess this means every shell sources /etc/bash.bashrc. I thought only patched bashes would do this, but then the PKGBUILD: _bashconfig=(... -DSYS_BASHRC=\'\"/etc/bash.bashrc\"\' ...). So yep "export" is clearly not needed. (man page for bash needs an update)

Loading...