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!
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!
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
Opened by orbisvicis (orbisvicis) - Monday, 14 February 2011, 07:04 GMT
Last edited by Allan McRae (Allan) - Tuesday, 15 February 2011, 20:43 GMT
|
DetailsDescription:
$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
Tuesday, 15 February 2011, 20:43 GMT
Reason for closing: Not a bug
Additional comments about closing: See comments
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.
[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.
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).