Monday, 18 August 2014

Beauty of shopt

shopt is a builtin command which can be used to customize the way you interact with terminal is several ways. Some of them are:

Ignore typos in path while changing directory

Say you want to go to /home/alse/path and you type /home/alse/paht instead, the following command will intelligently take you to /home/alse/path

shopt -s cdspell

Make commands case insensitive in linux

To be frank I like case sensitiveness of commands in linux unlike in windows command prompt. It makes you more careful while writing scripts. However I know some people who would like case in-sensitiveness.
It is possible to do this using shopt command.

shopt -s  nocaseglob

Remove the need of 'cd' while changing directory

Tired of typing cd command before path? Try this

shopt -s autocd

Now you can simply type the path to go to that directory.

Store Multi-line commands in history

See this blog post

shopt -s lithist

Mail warn

If set, and a file that Bash is checking for mail has been accessed since the last time it was checked, the message "The mail in mailfile has been read" is displayed.

shopt -s mailwarn

SIGHUP by default

Bash will send SIGHUP to all jobs when an interactive login shell exits.

shopt -s huponexit