Shell Options
Linux Commands - Shells

Shell options allow you to modify the shell's behavior.

When you open a bash session, you can use the set command to modify bash behavior for that session.  Though it may seem a bit counterintuitive, you would use the "set -o" command to turn an option on, and the "set +o" command to turn an option off.

Lesson 12 / Lesson 14

Note:  Options that you set in this manner will disappear as soon as you log out of a bash session.  This includes when you close a terminal emulator window.

Here are some of the options that you can set:

emacs or vi
    You can use emacs key-commands to navigate the history list and edit the command line.  You can change this behavior to make bash recognize vi key-commands, instead.  This normally isn't advisable, though, since most vi key-commands consists of pressing only one letter.  This may cause bash to misinterpret other commands that you try to enter.
history
    This is on by default.   Turning it off causes bash to not keep a history list of past executed commands.
hashall
    This is also on by default.  It enables a hash table of requested commands, along with their locations.  This is for repeated use of commands.
monitor
    This option has to do with job control, which we haven't covered yet.  Setting this to on causes background processes to run in a separate group and to notify the console when they either end or complete.
noclobber
    This is off by default.  If you set it to on, you'll be able to prevent bash from overwriting an existing file with the redirect symbol (>).  
noexec
    No, this doesn't have anything to do with the -exec switch that you saw in the find chapter.  This is to allow you to perform syntax checking on script files without actually having to run the script files.
notify
    This also has to do with job control.  Setting this to on forces bash to immediately report terminated jobs to the console, rather than waiting until the next invocation of the jobs command.
verbose
    Setting this to on causes bash to echo any command that you enter back to the console before the command gets executed.


To show how this works, let's say that we want to set verbose to on.

    # set -o verbose
    echo -ne "\033]0;${USER}@${HOSTNAME%%.*}:${PWD/#$HOME/~}\007"
 
Notice how this option gets to work before you even enter a command.  Here, you see it echoing the string that causes the command prompt to show up.  Here's what you would get after entering "ls *.txt"

    # ls *.txt
    ls *.txt

    DHCP_example.txt         newtext.txt          testingthisthing.txt
    DHCP_install_error.txt   OinkCode.txt         test.txt
    findconf.txt             Postfix_install.txt  VSFTPD_install.txt
    forward_zone.txt         rootkit_urls.txt     yetanothertest.txt
    furthertext.txt          SpamAssassin.txt
    echo -ne "\033]0;${USER}@${HOSTNAME%%.*}:${PWD/#$HOME/~}\007"

Note how the "ls *.txt" command is echoed on the next line, before it starts returning output.  When the output from the ls command completes, bash again echos the string that shows the command prompt.

To set this option to off, you can enter "set +o verbose".

    # set +o verbose
    set +o verbose

As you can see, this command also gets echoed back before the option actually takes effect.  Look at one final example.

You can set the "noclobber" option to on by entering:

    # set -o noclobber
    
Now, if you try to use the redirection operator to overwrite an existing text file, you receive an error message.

    [# ls -a > filelisting.txt
    bash: filelisting.txt: cannot overwrite existing file
    
To turn the noclobber option back off, enter:
   
    # set +o noclobber
    

 


Copyright CyberMontana Inc. and BeginLinux.com
All rights reserved. Cannot be reproduced without written permission. Box 1262 Trout Creek, MT 59874