ksh, or if emulate ksh is in effect.
Capitalised words with underlines refer to shell options.
Syntax:Command line substitutions, globbing etc.:
- Shell word splitting: see question C1.
- Arrays are more csh-like than ksh-like:
- subscripts start at 1, not 0;
array[0]refers toarray[1];$arrayrefers to the whole array, not$array[0];- braces are unnecessary:
$a[1] == ${a[1]}, etc.- The
KSH_ARRAYSoption is now available.- Coprocesses are established by
coproc;|&behaves like csh.Command execution:
- Failure to match a globbing pattern causes an error (use
NO_NOMATCH).- The results of parameter substitutions are treated as plain text:
foo="*"; print $fooprints all files in ksh but*in zsh. (GLOB_SUBSThas been added to fix this.) On the other hand,foo=*does globbing immediately on the right hand side of the assignment (this has changed from 2.6-beta17; the old behaviour now requires the optionGLOB_ASSIGN).- The backslash in
$(echo '\$x')is treated differently: in ksh, it is not stripped, in zsh it is. (The`...`form gives the same in both shells.)$PSndo not do parameter substitution by default (usePROMPT_SUBST).- Globbing does not allow ksh-style `pattern-lists'. The table below lists equivalent zsh syntax.
The
Equivalent ksh-style pattern lists ksh zsh Meaning !(foo)^fooAnything but foo.foo1~foo2Anything matching foo1but notfoo2*.@(foo1|foo2|...)(foo1|foo2|...)One of foo1orfoo2or ...?(foo)(foo|)Zero or one occurrences of foo.*(foo)(foo)#Zero or more occurrences of foo.+(foo)(foo)##One or more occurrences of foo.^,~and#(but not `|')forms requireEXTENDED_GLOB..*Note that
~is the only globbing operator to have a lower precedence than/. For example,**/foo~*bar*matches any file in a subdirectory calledfoo, except wherebaroccurred somewhere in the path (e.g.users/barstaff/foowill be excluded by the~operator). As the**operator cannot be grouped (inside parentheses it is treated as*), this is the way to exclude some subdirectories from matching a**.
- Unquoted assignments do file expansion after ':'s (intended for
PATHs).integerdoes not allow-i.Aliases and functions:
- There is no
$ENVvariable (use/etc/zshrc,~/.zshrc; note also$ZDOTDIR).$PATHis not searched for commands specified at invocation without-c.Traps and signals:
- The order in which aliases and functions are defined is significant (function definitions with () expand aliases -- see question B3).
- Aliases and functions cannot be exported.
- There are no tracked aliases: command hashing replaces these.
- The use of aliases for key bindings is replaced by
bindkey.- Options are not local to functions (use
LOCAL_OPTIONS; note this may always be unset locally to propagate options settings from a function to the calling level).Editing:
- Traps are not local to functions.
TRAPERRhas becomeTRAPZERR(this was forced by UNICOS which hasSIGERR).Built-in commands:
- The options
emacs,gmacs,trackall,viraware not supported. Usebindkeyto change the editing behaviour:set -o {emacs,vi}becomebindkey -{e,v}'; for gmacs, go to emacs mode and use`bindkey \^t gosmacs-transpose-characters.Trackallis replaced byhashcmds.- The
keywordoption does not exist and-kis insteadinteractivecomments. (keywordwill not be in the next ksh release either.)- Management of histories in multiple shells is different:
- the history list is not saved and restored after each command.
\does not escape editing chars (use^V).- Not all ksh bindings are set (e.g. `<ESC>#'; try <ESC>q).
- # in an interactive shell is not treated as a comment by default.
Other idiosyncrasies:
- Some built-ins (
r, autoload, history, integer...) were aliases in ksh.- There is no built-in command
newgrp: use e.g.alias newgrp="exec newgrp"jobshas no-nflag.readhas no-sflag.- In
let "i = foo",foois evaluated as a number, not an expression (although inlet "i = $foo"it is treated as an expression).
selectalways redisplays the list of selections on each loop.
- Logout, rehash, source, (un)limit built-in commands.
- *rc file for interactive shells.
- Directory stacks.
- Cshjunkie*, ignoreeof options.
- The
CSH_NULL_GLOBoption.>&,|&etc. redirection.
(Note that>file 2>&1is the standard Bourne shell command for csh's>&file.foreach... loops; alternative syntax for other loops.- Alternative syntax
if ( ... ) ..., though this still doesn't work like csh: it expects a command in the parentheses. Alsofor,which).$PROMPTas well as$PS1,$statusas well as$?,$#argvas well as$#, ....- Escape sequences via % for prompts.
- Special array variables
$PATHetc. are colon-separated,$pathare arrays.!-type history (which may be turned off viasetopt nobanghist).- Arrays have csh-like features( see above).