1

bash refuses to give me the output of 'bind -p' when I pass it in with the -c switch:

bash -c 'bind -p'

but it works to type

bind -p

directly at the bash prompt, and it works to type something like

bash -c 'echo "hi"'

and zsh happily does exactly what bash refuses to do (well, the equivalent command in zsh):

zsh -c 'bindkey -L'

What on earth is going on???

iconoclast
  • 1,800
  • 2
  • 18
  • 30

2 Answers2

3

When you run bash with the -c option, bash runs in non-interactive mode. Apparently, the bind builtin doesn't generate output when bash is in non-interactive mode. You can force bash to interactive mode by giving the -i option. The following works for me:

bash -i -c 'bind -p'
Steven Monday
  • 13,599
  • 4
  • 36
  • 45
  • ok, for bonus points, can you explain why you and I are having it work this way, but Dennis Williamson is not? – iconoclast Nov 05 '10 at 23:28
  • @Brandon: I would need to know more about his shell environment to even begin to hazard a guess. – Steven Monday Nov 05 '10 at 23:56
  • 1
    @Brandon: Probably a version issue. `bind -c 'bind -p'` gives no output for me with Bash 3.2.39, but produces the same output as with `-i` or `set -o emacs` with Bash 4.1.15. Without `-i` or `set -o`, Bash 4 additionally emits `bash: line 0: bind: warning: line editing not enabled` on stderr. – Gilles 'SO- stop being evil' Nov 13 '10 at 15:20
0

OK, I have a partial answer that I just discovered after entering my question...

If I type

bash -c "set -o emacs && bind -p"

then it gives the output of the bind command. It seems that for some reason bash doesn't have a default key map, which is really odd.

(I had had something sourced by my .bash_profile which had an error--something that worked fine in zsh but which bash choked on (apparently bash doesn't allow using 'else' in scripts!?)--and so I just disabled it, figuring default settings would be cleaner anyway.)

It's almost unthinkable that bash doesn't default to either a vi or an emacs keymap. Or is there something else going on that is escaping me?

iconoclast
  • 1,800
  • 2
  • 18
  • 30