Bug 620435 - Please use printf instead of echo.
Summary: Please use printf instead of echo.
Keywords:
Status: CLOSED RAWHIDE
Alias: None
Product: Fedora
Classification: Fedora
Component: setup
Version: rawhide
Hardware: All
OS: Linux
medium
medium
Target Milestone: ---
Assignee: Ondrej Vasik
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2010-08-02 14:09 UTC by Roman Rakus
Modified: 2010-08-18 08:45 UTC (History)
4 users (show)

Fixed In Version: setup-2.8.25-1.fc15
Doc Type: Bug Fix
Doc Text:
Clone Of: 620408
Environment:
Last Closed: 2010-08-13 12:37:26 UTC
Type: ---
Embargoed:


Attachments (Terms of Use)

Description Roman Rakus 2010-08-02 14:09:17 UTC
+++ This bug was initially created as a clone of Bug #620408 +++

Description of problem:
Due to the fix of bug #142125 the default PROMPT_COMMAND has been set to a list of two commands.  This causes strange behaviour when the output of a background process might get flushed after the output of the first PROMPT_COMMAND echo and hence appear between the escape sequences which mark the X terminal title.  It also means the text doesn't appear in the terminal itself.

Version-Release number of selected component (if applicable):
bash-4.1.2-2.el6.x86_64

How reproducible:
Sometimes

Steps to Reproduce:
1. In xterm/gnome-terminal/Terminal run: yes &
2. while 'yes' is running: cat /var/log/yum.log (or whatever application which prints out something on the terminal and takes some time)
3. Look at the terminal title -- it would read something like "tsmetana@localhost:~/bash_testy y y y y y"
4. if not GOTO 2.
  
Actual results:
The text printed in the terminal title was not printed in the terminal window (this can be verified by running something else than 'yes' -- e.g. a simple c-program which outputs a number sequence)

Expected results:
The output of PROMPT_COMMAND shouldn't get mixed with the other text that goes to the terminal.

Additional info:
There is a simple way to check the more commands in PROMPT_COMMAND can have unusual consequence -- try to add sleep between the two commands:

export PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME%%.*}:${PWD/#$HOME/~}"; sleep 1; echo -ne "\007"'

Now just press enter and some random keys on the keyboard, then look at the xterm title -- it would contain the keys you pressed.  Note that the sleep only increases the chance for this to happen.

I'm not actually sure how to solve the problem properly: maybe the bug #142125 has to be fixed some other way and PROMPT_COMMAND should be reverted to the old value with just one echo command.

--- Additional comment from rrakus on 2010-08-02 09:42:28 EDT ---

I guess we should use `printf' instead of `echo'.

--- Additional comment from rrakus on 2010-08-02 10:08:23 EDT ---

PROMPT_COMMAND='printf "\033]0;%s@%s:%s\007" "${USER}" "${HOSTNAME%%.*}" "${PWD/#HOME/~}"'

works for me. Reassigning to setup.

Comment 1 Ondrej Vasik 2010-08-13 12:37:26 UTC
Built as setup-2.8.25-1.fc15, closing RAWHIDE.

Comment 2 Pete Zaitcev 2010-08-18 02:56:33 UTC
See possible regression in bug 624900.

Comment 3 Tomas Smetana 2010-08-18 08:20:26 UTC
I'm sorry. I should have noticed before: there's yet another problem with the change: There is a missing '$' before HOME... The PROMPT_COMMAND should look like this:

PROMPT_COMMAND='printf "\033]0;%s@%s:%s\007" "${USER}" "${HOSTNAME%%.*}" "${PWD/#$HOME/~}"'
                                                                                   ^^^^^^^

As for Pete's problem with screen: I don't think it's this change that caused it (tested on F-13 -- I put the new PROMPT_COMMAND definition in my ~/.bashrc using the Xfce terminal):

[tsmetana@zaphod ~]$ echo $TERM
screen
[tsmetana@zaphod ~]$ echo $PROMPT_COMMAND 
printf "\033]0;%s@%s:%s\007" "${USER}" "${HOSTNAME%%.*}" "${PWD/#$HOME/~}"
[tsmetana@zaphod ~]$ pstree | grep screen
     |      `-sshd---sshd---bash---screen---screen---bash-+-grep

Regards.

Comment 4 Ondrej Vasik 2010-08-18 08:45:07 UTC
Tomas - it was really problem caused by the change to printf - I did a typo there... this should be fixed in setup-2.8.26-1.fc15 ... 
You are right about the missing $ ... will fix that in next setup build ...


Note You need to log in before you can comment on or make changes to this bug.