Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Substituting newline on a string

2008/7/1 Javier Alvarado <quijotista@xxxxxxxxx>:
> I have a seemingly trivial problem that I have not be able to solve. How do I replace a newline in a string with somethinge else, like ' ' (or better yet '\n')?
> I've tried
> cmd=${1/$/ /}
> cmd=${1/\n/ /}
> cmd=${1/\r/ /}
> plus any thing else I could think of without success.
> In case it matters, I'm trying to put the command being executed into my xterm title bar from preexec() and I want to be able to handle multi-line commands.
> Thanks for any help.

My function for this has some possibly rxvt-unicode specific bits in it, but
maybe it helps.

function ct() {
  local MATCH
  if [[ "$1" = "-e" ]]; then
    #nulls terminate the string when printed, so change them
    printf '\e]0;%s\007' ${${${2//$'\x00'/\^@}//
  elif [[ "$1" = "-t" ]]; then
    ct -e "$3" > /dev/pts/$pts
    ct -e "$*"

Instead of that crazy printf, you can try this other crazy printf:
printf '\e]0;%s\007' ${${2//

Also, pasting that I realize that the answer to your question is either
what Frank said, or:
/ /}

Mikael Magnusson

Messages sorted by: Reverse Date, Date, Thread, Author