Korn Shell Options

   

Korn Shell: Unix and Linux Programming Manual, Third Edition, The
By Anatole Olczak

Table of Contents
Chapter 7.  The Environment


The Korn shell has a number of options that specify your environment and control execution. There are options that cause background jobs to be run at a lower priority, prevent files from being overwritten with redirection operators, disable filename expansion, specify the vi-style in-line command editor, and more.

Table 7.2 lists some of the Korn shell options, along with the default values (these may differ on your system). All of the options are listed in Appendix E.

Table 7.2. Some Korn Shell Options

set a, set o allexport

automatically export variables when defined

set o bgnice

execute all background jobs at a lower priority

set o emacs, set o gmacs

use emacs/gmacs in-line editor

set o ignoreeof

do not exit on end of file; use exit (default Ctl-d)

set o markdirs

display trailing / on directory names resulting from file name substitution

set m, set o monitor

enable job control (system dependent)

set n, set o noexec

read commands without executing them

set o noclobber

prevent I/O redirection from truncating existing files

set f, set o noglob

disable file name expansion

set u, set o nounset

return error on substitution of unset variables

set h, set o trackall

make commands tracked aliases when first encountered

set o vi

use vi-style editor for in-line editing

set x, set o xtrace

display commands and arguments as they are executed

Enabling/Disabling Options

Korn shell options are enabled with the set ooption or set ?/span>option command. For example, the noglob option disables file name substitution and can be set using either of these commands :

 $ set  f 

or

 $ set  o noglob 

Options can also be enabled by specifying them on the ksh command line. Here, a Korn subshell is started with the emacs option enabled:

 $ ksh  o emacs 

Options can be disabled with the set +o option or set +option command. In this example, the noglob option is disabled:

 $ set +o noglob 
The ignoreeof Option

If this option is enabled, you get this message when you try to log off using Ctl-d:

 $ set  o ignoreeof  $ Ctl-d  Use 'exit' to terminate this shell 

By default, this option is disabled.

The markdirs Option

When enabled, a trailing / is appended to directory names resulting from file name substitution. It's like the ls o or ?span>F options, except that you only see the results on file name substitution, not on directory listings. This means that / is added to directory names when you do this:

 $ ls * 

but not this:

 $ ls 

By default, the markdirs option is disabled.

The noclobber Option

The noclobber option prevents I/O redirection from truncating or clobbering existing files. Let's enable the option and give it a try:

 $ set  o noclobber  $ ls>ls.out  $ ls>ls.out  /bin/ksh: ls.out: file already exists 

If noclobber is enabled, and you really want to overwrite a file, use the >| operator:

 $ ls>|ls.out 

By default, this option is disabled.

The nounset Option

If the nounset option is disabled, then the Korn shell interprets unset variables as if their values were null.

 $ unset X  $ print "X is set to: $X"  X is set to: 

If enabled, the Korn shell displays an error message when it encounters unset variables and causes scripts to abort:

 $ set  o nounset  $ unset X  $ print $X  /bin/ksh: X: parameter not set 

Displaying the Current Settings

The setting of the current options is displayed with the set o command. The first field is the option name, and the second field shows if the option is enabled or disabled:

 $ set  o  allexport        off  bgnice           on  emacs            off  errexit          off  gmacs            off  ignoreeof        off  interactive      on  keyword          off  markdirs         off  monitor          on  noexec           off  noclobber        off  noglob           off  nolog            off  nounset          off  privileged       off  restricted       off  trackall         off  verbose          off  vi               on  viraw            on  xtrace           off 

Command-line Options

Besides the options from the set command, the following options can also be specified on the ksh command line:

c string

read and execute the commands from string

i

execute in interactive mode

r

run a restricted shell

s

read commands from standard input

These cannot be enabled with the set command.


       
    Top
     



    Korn Shell. Unix and Linux Programming Manual, Third Edition
    Korn Shell. Unix and Linux Programming Manual, Third Edition
    ISBN: N/A
    EAN: N/A
    Year: 2000
    Pages: 177

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net