1

I'm using bash version 4.3.48:

$ bash --version
GNU bash, version 4.3.48(1)-release (x86_64-pc-linux-gnu)

I'm trying to define a key binding, using the key sequence C-x r, to reload the configuration of bash + readline. Thanks to @Gilles, I included this code in my ~/.bashrc:

bind    '"\e[99i~": re-read-init-file'
bind -x '"\e[99b~": . ~/.bashrc'
bind    '"\C-xr":   "\e[99i~\e[99b~"'

It works, except that bash writes an error message when I hit C-x r, which I don't understand:

\udccf\udccf\udccf\udccf\udccf\udccf: command not found

I thought that maybe it was due to an interaction with some other settings that I changed, so I deleted everything in ~/.bashrc, except for the 3 lines defining the key binding C-x r.

But there's still an error message:

: command not found

So, I tried a simpler bashrc with only one key binding:

bind -x '"\C-xr": . ~/.bashrc'

This time, hitting C-x r produces the error:

\udccf
      : command not found

However, if I comment the line bind -x '"\C-xr": . ~/.bashrc' in my bashrc file, and I execute the command in an interactive bash shell, then everything works fine. No error message, and the configuration is properly re-sourced.

So, I guess I should write a guard around this key binding to prevent bash from re-defining it, if it has already been done. But I don't know how to test the existence of a key binding. Besides, I would like to better understand what happens with these errors.


I don't know if it matters, but I never start bash directly, I always start if from zsh. When I want to test some command that I'm going to write in a bash script, I open a terminal (using zsh as the default shell), then I execute bash from there. So, maybe bash inherits some environment variable from zsh which causes the first error message?

Also, as it was asked in the comment section, here's the output of hexdump -C ~/.bashrc with only the 3 key bindings:

00000000  62 69 6e 64 20 20 20 20  27 22 5c 65 5b 39 39 69  |bind    '"\e[99i|
00000010  7e 22 3a 20 72 65 2d 72  65 61 64 2d 69 6e 69 74  |~": re-read-init|
00000020  2d 66 69 6c 65 27 0a 62  69 6e 64 20 2d 78 20 27  |-file'.bind -x '|
00000030  22 5c 65 5b 39 39 62 7e  22 3a 20 2e 20 7e 2f 2e  |"\e[99b~": . ~/.|
00000040  62 61 73 68 72 63 27 0a  62 69 6e 64 20 20 20 20  |bashrc'.bind    |
00000050  27 22 5c 43 2d 78 72 22  3a 20 20 20 22 5c 65 5b  |'"\C-xr":   "\e[|
00000060  39 39 69 7e 5c 65 5b 39  39 62 7e 22 27 0a        |99i~\e[99b~"'.|
0000006e

Here's the hex dump with a bashrc containing only bind -x '"\C-xr": . ~/.bashrc':

00000000  62 69 6e 64 20 2d 78 20  27 22 5c 43 2d 78 72 22  |bind -x '"\C-xr"|
00000010  3a 20 2e 20 7e 2f 2e 62  61 73 68 72 63 27 0a     |: . ~/.bashrc'.|
0000001f

And here's my full bashrc:

case "$-" in
  *i*) ;;
  *) return ;;
esac
[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"
if [ -z "${debian_chroot:-}" ] && [ -r /etc/debian_chroot ]; then
  debian_chroot=$(cat /etc/debian_chroot)
fi
PS1="${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ "
alias cdr='cd "$(ls -dt */ | head -1)"'
export HISTCONTROL="ignoreboth:erasedups"
export HISTIGNORE="clear:history:"
export HISTFILE="${HOME}/.bash_eternal_history"
export HISTFILESIZE=
export HISTSIZE=
export HISTTIMEFORMAT="[%F %T] "
export PROMPT_COMMAND="history -a; history -c; history -r; ${PROMPT_COMMAND}"
cd() {
  if [ $# -eq 2 ]; then
    builtin cd "${PWD/$1/$2}"
  elif [ $# -eq 1 ]; then
    builtin cd "$1"
  else
    builtin cd
  fi
}
shopt -s autocd
shopt -s checkwinsize
shopt -s globstar
shopt -s histappend
shopt -s histreedit
shopt -s histverify
. /usr/share/bash-completion/bash_completion
. ~/.fzf.bash
. ~/.shrc
bind '" ": magic-space'
bind '"\C-xc": "\C-a\C-kvimdiff <() <()\C-b\C-b\C-b\C-b\C-b"'
bind '"\C-xf":  character-search'
bind '"\C-xF":  character-search-backward'
bind    '"\e[99i~": re-read-init-file'
bind -x '"\e[99b~": . ~/.bashrc'
bind    '"\C-xr":   "\e[99i~\e[99b~"'
bind '"\C-x\C-s": "sudo !!\C-m\C-m"'
bind -x '"\C-x\C-t": fzf-file-widget'
bind '"\C-t": transpose-chars'
bind '"\C-x\C-v": "\C-e | vim -R -\C-m"'
bind '"\em": "\C-aman \ef\C-k\C-m"'
bind '"\e\C-b":  "\C-e >/dev/null 2>&1 &\C-m"'

Edit:

I've tried to wrap the command . ~/.bashrc inside a function, and call the latter in the key binding. Using the following syntax:

bind    '"\e[99i~": re-read-init-file'
bind -x '"\e[99b~": MyFunc'
bind    '"\C-xr":   "\e[99i~\e[99b~"'
MyFunc () {
  . ~/.bashrc
}

And I've discovered that the error was influenced by the length of the name of the function. Here's a table, where the left column contains different names for the function, and where the right column contains the error messages (if any):

┌───────────────────┬─────────────────────────────────────────────────────────────────────────────────────────────┐
│ a                 │ \udc99: command not found                                                                   │
│ ab                │ \udc92: command not found                                                                   │
│ abc               │ : command not found                                                                         │
│ abcd              │ \udcdf\udcdf\udcdf\udcdf\udcdf\udcdf\udcdf\udcdf\udcdf\udcdf\udcdf\udcdf: command not found │
│ abcde             │ \udcdf\udcdf\udcdf\udcdf\udcdf\udcdf\udcdf\udcdf\udcdf\udcdf\udcdf: command not found       │
│ abcdef            │ \udcdf\udcdf\udcdf\udcdf\udcdf\udcdf\udcdf\udcdf\udcdf\udcdf: command not found             │
│ abcdefg           │ no error                                                                                    │
│ abcdefgh          │ : command not found                                                                         │
│ abcdefghi         │ \udcdf\udcdf\udcdf\udcdf\udcdf\udcdf\udcdf: command not found                               │
│ abcdefghij        │ \udcdf\udcdf\udcdf\udcdf\udcdf\udcdf: command not found                                     │
│ abcdefghijk       │ \udcdf\udcdf\udcdf\udcdf\udcdf: command not found                                           │
│ abcdefghijkl      │ \udcdf\udcdf\udcdf\udcdf: command not found                                                 │
│ abcdefghijklm     │ \udcdf\udcdf\udcdf: command not found                                                       │
│ abcdefghijklmn    │ \udcdf\udcdf: command not found                                                             │
│ abcdefghijklmno   │ \udcdf: command not found                                                                   │
│ abcdefghijklmnop  │ : command not found                                                                         │
│ abcdefghijklmnopq │ no error                                                                                    │
└───────────────────┴─────────────────────────────────────────────────────────────────────────────────────────────┘

I also tried a different function where I reconnect the input of the . ~/.bashrc command to the terminal (inspiration from here):

bind    '"\e[99i~": re-read-init-file'
bind -x '"\e[99b~": MyFunc'
bind    '"\C-xr":   "\e[99i~\e[99b~"'
MyFunc () {
  . ~/.bashrc </dev/tty
}

Here are the results:

┌──────────────────────┬──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│ a                    │ 9}: command not found                                                                                                │
│ ab                   │ \udcdd: command not found                                                                                            │
│ abc                  │ : command not found                                                                                                  │
│ abcd                 │ no error                                                                                                             │
│ abcde                │ no error                                                                                                             │
│ abcdef               │ no error                                                                                                             │
│ abcdefg              │ no error                                                                                                             │
│ abcdefgh             │ : command not found                                                                                                  │
│ abcdefghi            │ \udcdf\udcdf\udcdf\udcdf\udcdf\udcdf\udcdf: command not found                                                        │
│ abcdefghij           │ \udcdf\udcdf\udcdf\udcdf\udcdf\udcdf: command not found                                                              │
│ abcdefghijk          │ \udcdf\udcdf\udcdf\udcdf\udcdf: command not found                                                                    │
│ abcdefghijkl         │ \udcdf\udcdf\udcdf\udcdf: command not found                                                                          │
│ abcdefghijklm        │ \udcdf\udcdf\udcdf: command not found                                                                                │
│ abcdefghijklmn       │ \udcdf\udcdf: command not found                                                                                      │
│ abcdefghijklmno      │ \udcdf: command not found                                                                                            │
│ abcdefghijklmnop     │ : command not found                                                                                                  │
│ abcdefghijklmnopq    │ no error                                                                                                             │
│ abcdefghijklmnopqr   │ no error                                                                                                             │
│ abcdefghijklmnopqrs  │ no error                                                                                                             │
│ abcdefghijklmnopqrst │ \udccf\udccf\udccf\udccf\udccf\udccf\udccf\udccf\udccf\udccf\udccf\udccf\udccf\udccf\udccf\udccf$: command not found │
└──────────────────────┴──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
  • 1
    Can you add head -n 2 .bashrc | hexdump -C? – Michael Homer Jun 11 '17 at 9:46
  • 1
    Note that octal 317 is hex CF and U+DCCF is in the low surrogate range (invalid in UTF-8, never appears alone). It seems like there's something odd, possibly invisible, within the file. – Michael Homer Jun 11 '17 at 9:51
  • 1
    Ok, more usefully, can you give a hexdump of the relevant lines from the file, wherever they are? You can just copy out from the middle when they start. If anything else unprintable appears include that too - the only thing should be 0a (LF). – Michael Homer Jun 11 '17 at 9:53
  • @MichaelHomer I removed all the comments and empty lines in my bashrc, and re-executed the hexdump command. I also included my whole bashrc. Thank you for your help. – user547381 Jun 11 '17 at 10:01
  • @MichaelHomer I'm sorry, I didn't fully understand your request the first time. But I think I have now. I've included the hex dump of only the key binding lines. I also removed the question relative to zsh, as it is probably a different issue. I'll write another question for it. Again, thank you for your help. – user547381 Jun 11 '17 at 11:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.