2

This question was about how to delete the last word in bash with ctrl-backspace. As already mentioned there, different Linux distros (or different Unices in general) behave differently: Some produce ^H, some produce ^? if Ctrl+Backspace is pressed.

How can I find out in some automatic way (so it can be used in a script) which convention is followed?

2

There is no standard way to ask about control-backspace.

The conventional way to ask about the backspace key is in the terminal database, e.g., look at the output of

tput kbs

If your terminal is configured to match the TERM value, that gives the "backspace" key.

Some terminals (originally rxvt, later xterm and now "several" undocumented) implement control-backspace as the "other" choice (^H where "backspace" sends ^?, etc). Some terminals ignore the control modifier. But for those that use it, that inference is as far as you can go.

Further reading:

  • So there is absolutely no chance to simulate the keystroke (like with xdotool under X11) and save the result? – wolf-revo-cats Apr 24 '16 at 16:40
  • That wouldn't help if you're running in a virtual console, and also wouldn't help if you are running via ssh. – Thomas Dickey Apr 24 '16 at 16:41
  • I know, just something similar. – wolf-revo-cats Apr 24 '16 at 16:42

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.