19. Options

Some options have already been mentioned; here are a few more:

Using the AUTO_CD option, you can simply type the name of a directory, and it will become the current directory.

Example 19.1: AUTO_CD without cd
% cd /
% setopt autocd
% bin
% pwd
/bin
% ../etc
% pwd
/etc

With CDABLE_VARS, if the argument to cd is the name of a parameter whose value is a valid directory, it will become the current directory.

Example 19.2: CDABLE_VARS via parameter
% setopt cdablevars
% foo=/tmp
% cd foo
/tmp

CORRECT turns on spelling correction for commands, and the CORRECT_ALL option turns on spelling correction for all arguments.

Example 19.3: CORRECT and CORRECT_ALL
% setopt correct
% sl
zsh: correct `sl' to `ls' [nyae]? y
% setopt correctall
% ls x.v11r4
zsh: correct `x.v11r4' to `X.V11R4' [nyae]? n
/usr/princton/src/x.v11r4 not found
% ls /etc/paswd
zsh: correct to `/etc/paswd' to `/etc/passwd' [nyae]? y
/etc/passwd

If you press y when the shell asks you if you want to correct a word, it will be corrected. If you press n, it will be left alone. Pressing a aborts the command, and pressing e brings the line up for editing again, in case you agree the word is spelled wrong but you don’t like the correction.

Normally, a quoted expression may contain a newline:

Example 19.4: Newlines in quoted strings
% echo '
> foo
> '

foo

%

With CSH_JUNKIE_QUOTES set, this is invalid, as it is in csh.

Example 19.5: CSH_JUNKIE_QUOTES rejects
% setopt cshjunkiequotes
% ls 'foo
zsh: unmatched '

GLOB_DOTS lets files beginning with a . be matched without explicitly specifying the dot. This can also be specified for a particular pattern by appending (D) to it.

Example 19.6: GLOB_DOTS matches dots
% ls -d *x*
Mailboxes
% ls -d *x*(D)
.exrc         .pnewsexpert  .xserverrc
.mushexpert   .xinitrc      Mailboxes
% setopt globdots
% ls -d *x*
.exrc         .pnewsexpert  .xserverrc
.mushexpert   .xinitrc      Mailboxes

HIST_IGNORE_DUPS prevents the current line from being saved in the history if it is the same as the previous one; HIST_IGNORE_SPACE prevents the current line from being saved if it begins with a space.

Example 19.7: HIST_IGNORE_DUPS and SPACE
% PROMPT='%h> '
39> setopt histignoredups
40> echo foo
foo
41> echo foo
foo
41> echo foo
foo
41> echo bar
bar
42> setopt histignorespace
43>  echo foo
foo
43>  echo fubar
fubar
43>  echo fubar
fubar

IGNORE_BRACES turns off csh-style brace expansion.

Example 19.8: IGNORE_BRACES disables braces
% echo x{y{z,a},{b,c}d}e
xyze xyae xbde xcde
% setopt ignorebraces
% echo x{y{z,a},{b,c}d}e
x{y{z,a},{b,c}d}e

IGNORE_EOF forces the user to type exit or logout, instead of just pressing Ctrl+D.

Example 19.9: IGNORE_EOF requires exit
% setopt ignoreeof
% ^D
zsh: use 'exit' to exit.

INTERACTIVE_COMMENTS turns on interactive comments; comments begin with a #.

Example 19.10: INTERACTIVE_COMMENTS with #
% setopt interactivecomments
% date # this is a comment
Fri May 24 06:54:14 EDT 1991

NO_BEEP makes sure the shell never beeps.

NO_CLOBBER prevents you from accidentally overwriting an existing file.

Example 19.11: NO_CLOBBER blocks overwrite
% setopt noclobber
% cat /dev/null >~/.zshrc
zsh: file exists: /u/pfalstad/.zshrc

If you really do want to clobber a file, you can use the >! operator. To make things easier in this case, the > is stored in the history list as a >!:

Example 19.12: Force overwrite with >!
% cat /dev/null >! ~/.zshrc
% cat /etc/motd > ~/.zshrc
zsh: file exists: /u/pfalstad/.zshrc
% !!
cat /etc/motd >! ~/.zshrc
% ...

RC_QUOTES lets you use a more elegant method for including single quotes in a singly quoted string:

Example 19.13: RC_QUOTES doubled quotes
% echo '"don'\''t do that."'
"don't do that."
% echo '"don''t do that."'
"dont do that."
% setopt rcquotes
% echo '"don''t do that."'
"don't do that."

Finally, SUN_KEYBOARD_HACK wins the award for the strangest option. If a line ends with `, and there are an odd number of them on the line, the shell will ignore the trailing `. This is provided for keyboards whose RETURN key is too small, and too close to the ` key.

Example 19.14: SUN_KEYBOARD_HACK trailing backtick
% setopt sunkeyboardhack
% date`
Fri May 24 06:55:38 EDT 1991