Member Avatar for Member #1127230

Hello everyone.

I realize that this may be an elementary question, but all of my searches for answers have not given me a satisfactory result. In my ubuntu server machine, I typed in [after examining my stty settings] werase='^I' as I was configuring the terminal to my likings.

All was fine after I made that change and the command worked beautifully. After I logged out and logged back in, I could not use that shortcut anymore and I had to manually reprogram it to use it again.

Could anyone suggest how I can fix this problem and make the setting persistent?'

Thanks in advance for the input.

Dani AI

Generated

Good to know: stty changes settings only for the tty attached to the current session. When you log in again (or open a new terminal/SSH), you get a fresh pty with default settings, so the change disappears. Make it stick by running stty from a shell startup file that executes for interactive sessions. In Bash, login shells read one of ~/.bash_profile, ~/.bash_login, or ~/.profile, while interactive non-login shells read ~/.bashrc. A safe pattern is:

# in ~/.bashrc
if [ -t 0 ]; then
  stty werase '^I'
fi

The [ -t 0 ] guard avoids the common “stty: standard input: Inappropriate ioctl for device” error in non-interactive contexts (cron, some SSH commands). stty accepts control chars in the ^c form, and werase is the word-erase character. (gnu.org)

One caveat: binding werase to Tab (^I) can override Bash’s default Tab completion, because Readline normally binds TAB to the complete command, and it can mirror kernel special chars via the bind-tty-special-chars setting. If you want to keep completion, either pick a different key for werase or do the keybinding entirely in Readline as suggested (via ~/.inputrc). That approach applies across programs that use Readline. (gnu.org)

Quick checks and troubleshooting:

  • Verify the tty setting took by running stty -a and looking for werase = ^I. (man7.org)
  • See what Readline bound for word erase: bind -P | grep backward-kill-word. If TAB shows there, it will preempt completion. Re-source your rc file as noted, or open a new shell, after changes. (gnu.org)

Recommended Answers

All 3 Replies

You could try the answer here Click Here using "\C-i" instead of "\C-w". Of course, you need to restart bash after modifying ~/.bashrc.

Of course, you need to restart bash after modifying ~/.bashrc.

Actually you don't have to restart bash at all. You can re-load/re-source any of the changed config files in the running shell using the dot command ('.') which is a built-in. So after changing .bashrc, you can re-load it by using the following command:

. ~/.bashrc

This will reload and execute the config file, any changes that were made to the .bashrc file will then affect the running shell. No need to shut down bash and open a new instance. Just use the dot command in all open terminals to re-load the latest config!

As it is a built-in, there is no man page, but the help command will show you more information about it:

help .
commented: good point +14
Member Avatar for Member #1127230

Thank you everyone for your inputs!

They helped me fix it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.