Hello there folks!
I have been using
[BASH](http://en.wikipedia.org/wiki/Bash_%28Unix_shell%29) for quite a long time. Yet I feel like there is a lot that I don’t know. The irony is that I am doing the BASH and Linux Basics training for new hires at my firm. I am not that bad, you see. It is just that there is so much to know. And I am never happy with what I know.
I mostly use the terminal at work. Though Ubuntu has given me a beautiful GUI, I still do a lot of stuff on the terminal, like writing scripts and other code. I use Ubuntu at home. At work, I used to maintain systems that worked on csh and bash. Though they are pretty much Linux Shells, they are very different in terms of behaviour and syntax when it comes to scripting.
I don’t know if you guys use bash’s auto-completion a lot. I was so used to typing a command and then searching my command history by just pressing the up arrow key at work that I thought I’d just do the same at home. So in my virtual box Ubuntu I edited my
~/.bash_profile file and added the following lines:
#bind up and down arrow keys to search partly typed commands from history bind '"\\e\[A": history-search-backward' bind '"\\e\[B": history-search-forward' ```Notice the bind keyword? That is what binds a particular key to a certain method. So if you knew what the mapping of key is to its character-set and you wanted to make it do something that it would otherwise not do, you could use the bind tool and map it to do something interesting and useful. So in my case, I wanted to bind the up arrow and the down arrow to the corresponding history search forward and backward functions. This would give me the ability to type a command partially and search back and forth in my history of commands by just pressing the up arrow or down arrow keys. I don't even have to type ctrl-r to do a search separately which already available by default. Cool isn't it? Now you must be wondering how to get the character-set that represents a certain key on my keyboard. So to get that all you have to do is use the read tool in bash command line. So let me show you how. Type `read` on command line and then press the key for which you want the mapping and you have the mapping:
That's it you got the `up-arrow's` key mapping which is `^[[A` and `down-arrow's` key mapping which is `^[[B`. But that isn't what I have mentioned in my `~/.bash_profile`. Yes I know. I wasn't lying. I am just about to explain why it looks different there. The `^[` key maps to the `Esc` key. So on the command line to make it easier for the interpreter to understand what the key actually is, we use `\e` to denote that part. Followed by the everything that follows `^[` in the key map that you got from the `read` command. Now you know the key map and you can bind it to what ever you want to that `bash` would allow you to. But where do you find things that `bash` allows you to modify? Good question if you really did ask that. It can be found here: `/etc/inputrc`. I hope that helps.