When I try bind some commands with bind -x bash utility, I can't see my stdin input on terminal.


root> # bind -x '"\C-p": su dargod'

When I type ctrl+P - I login to user dargod, but all what I types not shows. Same situation with bind ssh command for connect.

How I can normally interract with shell?


Bash 3.1.17 (CentOS 5)
Bash 4.2.46 (CentOS 7)
Bash 4.1.2 (CentOS 6)
Bash 5.0.7 (Arch Linux)
Bash 4.2.45 (Gentoo)

  • Your command has a typo, a forgotten :: bind -x '"\C-p": su dargod' With the : in place I can't reproduce you issue using bash 5.0.7. Without the :, I get an error message when executing the bind command. Please edit your question and add information about what version of bash you are using on what Unix. – Kusalananda Aug 2 at 20:30
  • sure I used :, just missed when copying, edited – Dargod Aug 2 at 20:32
  • What is the info? Are those all the machines you have tried on or does your machine shift between operating systems and bash versions? – Jesse_b Aug 2 at 20:45
  • Yes, In the info indicated on which systems I tried and with which versions bash – Dargod Aug 2 at 20:48

Commands bound to a key are meant to be used as part of line editing. They run with the terminal in raw mode, with bash expecting to handle each key press. Most commands expect to run with the terminal in cooked mode, where the terminal reads one line at a time and echoes the input.

To run a command that takes over the terminal interaction, temporarily set the terminal to cooked mode.

bind -x '"\C-p": _bash_stty_save=$(stty -g); stty sane; su dargod; stty $(_bash_stty_save)'

Note that this may still not work perfectly, because you're doing sometihng that bash doesn't expect. Bindings are not the right tool to run a command. To define a shortcut for a command, use an alias.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.