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]
;$array
refers to the whole array, not$array[0]
;- braces are unnecessary:
$a[1] == ${a[1]}
, etc.- The
KSH_ARRAYS
option 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 $foo
prints all files in ksh but*
in zsh. (GLOB_SUBST
has 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.)$PSn
do 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)
^foo
Anything but foo
.foo1~foo2
Anything matching foo1
but notfoo2
*.@(foo1|foo2|...)
(foo1|foo2|...)
One of foo1
orfoo2
or ...?(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 wherebar
occurred somewhere in the path (e.g.users/barstaff/foo
will 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
PATH
s).integer
does not allow-i
.Aliases and functions:
- There is no
$ENV
variable (use/etc/zshrc
,~/.zshrc
; note also$ZDOTDIR
).$PATH
is 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.
TRAPERR
has becomeTRAPZERR
(this was forced by UNICOS which hasSIGERR
).Built-in commands:
- The options
emacs
,gmacs
,trackall
,viraw
are not supported. Usebindkey
to change the editing behaviour:set -o {emacs,vi}
becomebindkey -{e,v}
'; for gmacs, go to emacs mode and use`bindkey \^t gosmacs-transpose-characters
.Trackall
is replaced byhashcmds
.- The
keyword
option does not exist and-k
is insteadinteractivecomments
. (keyword
will 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"
jobs
has no-n
flag.read
has no-s
flag.- In
let "i = foo"
,foo
is evaluated as a number, not an expression (although inlet "i = $foo"
it is treated as an expression).
select
always 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_GLOB
option.>&
,|&
etc. redirection.
(Note that>file 2>&1
is 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
).$PROMPT
as well as$PS1
,$status
as well as$?
,$#argv
as well as$#
, ....- Escape sequences via % for prompts.
- Special array variables
$PATH
etc. are colon-separated,$path
are arrays.!
-type history (which may be turned off viasetopt nobanghist
).- Arrays have csh-like features( see above).