Bash – Difference Between .bashrc and .inputrc

bashbashrcinputrcshell-script

I am new to the unix system, and find it interesting to create customized functions and configurations in the setting files like .bashrc and .inputrc.

However, I don't understand the differences between the two. For example, when I created alias, I put them in .bashrc.

Example 1: alias ...='cd ../../'

When I create operations like using arrow key to look for previous or next command, I put the command in .inputrc.

Example 2: "\e[A": history-search-backward

Why I need to put them in different setting files? How do I distinguish when to put what where?

Thank you in advance!

Best Answer

Settings that are in the .inputrc file affect all programs that use the GNU readline library, not just bash. Think of the .inputrc file as being a configuration file for GNU Readline similar to how .bashrc is a configuration file for bash.

GNU Readline is described as:

... A set of functions for use by applications that allow users to edit command lines as they are typed in.

To clarify a bit further, settings that are in the .bashrc file only affect bash. If you'd like to optionally run bash without GNU Readline support or usage, you can invoke bash with the --noediting option as follows: bash --noediting. You can find out more about bash options here.

To answer your last question of

How do I distinguish when to put what where?

If you'd like an option to affect all programs on your system that use the GNU Readline library, .inputrc would be the prime choice. Elsewise, if you simply want to configure your bash session, .bashrc would be the best choice.

Related Question