Tutorial 1: Restore Up/Down History Key

THIS BLOG HAS MOVED TO:

https://bashtheshell.github.io

 

Today, I ran into an issue that I will explain in a moment. I tried searching around the Net for an answer. As you guess it, I didn’t get any hit.

The issue is that I was unable to restore the Up and Down history keys to recall the recent commands after disabling the in-line command editing feature. I was logged into my Solaris system using bash shell. Here is what I did.

This is the command to enable in-line command editing using vi. (Please note that this only work in bash, korn, c, and tcsh shell, but I can only speak for bash):

bash-3.2$ set -o vi

After checking out the command, I reverted the setting using this command:

bash-3.2$ set +o vi

I tried going back to my previous commands using the Up key, but it didn’t work. I get this instead.

bash-3.2$ set +o vi
bash-3.2$
bash-3.2$ ^[[A

I freaked out. I was following the examples in the book, but it didn’t address that issue. The Net gave no answer. So, I knew the first two commands were the culprits, but I just didn’t know why yet. The book I read mentioned that I can see a complete list of set‘s special options using either commands (both commands show different outputs but give the same result):

bash-3.2$ set -o
bash-3.2$ set +o

The first command produced an output of list that was easier to read than the second command. This is the output from the first command:

bash-3.2$ set -o
allexport off
braceexpand on
emacs off
errexit off
errtrace off
functrace off
hashall on
histexpand on
history on
ignoreeof off
interactive-comments on
keyword off
monitor on
noclobber off
noexec off
noglob off
nolog off
notify off
nounset off
onecmd off
physical off
pipefail off
posix off
privileged off
verbose off
vi off
xtrace off

This is the output from the second command:

bash-3.2$ set +o
set +o allexport
set -o braceexpand
set +o emacs
set +o errexit
set +o errtrace
set +o functrace
set -o hashall
set -o histexpand
set -o history
set +o ignoreeof
set -o interactive-comments
set +o keyword
set -o monitor
set +o noclobber
set +o noexec
set +o noglob
set +o nolog
set +o notify
set +o nounset
set +o onecmd
set +o physical
set +o pipefail
set +o posix
set +o privileged
set +o verbose
set +o vi
set +o xtrace

See the difference? Well, that’s not the cause though. I’m just showing you the differences between the outputs from both commands. Here’s what I did. I closed the terminal window and opened a new one. This time, I executed the set -o command before I  enabled and disabled the in-line command editing feature, so I can compare the list after the executions. One thing I noticed is that the emacs feature is enabled by default. When I executed the set -o vi, it automatically disabled the emacs feature because only one of the editors can be used at a time. When I disabled the vi, both features remain disabled. That’s when I couldn’t use the Up arrow key to get the recent commands. So, I enabled the emacs feature and… Voilà! I got the Up/Down arrows key working. I had no idea emacs was enabled the whole time, but I hate it. I thought this solved mystery would make an interesting post on my blog.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s