Zsh Home |Wikipedia: Z Shell |Reddit: Zsh
Z Shell is a POSIX-compatible shell, but with much more to offer. Script programs can be written in Z Shell, using modules and advanced variable and pattern handling, that rival compiled languages like C and that no standard POSIX shell could do. Following are some examples:
To replace the system 'sleep' command with a shell function that accepts floating point seconds, minutes, hours, days, or weeks:
function delay sleep { emulate -LR zsh -o extendedglob -o nullglob local -F 32 Delay if [[ $1 == (#b)(digit:(#c1,).(#c0,1)digit:(#c0,))(s|m|h|d|w|) ]] then if [[ $match[2] == (s|) ]] Delay=$[ $match[1] ] if [[ $match[2] == (m) ]] Delay=$[ $match[1] * 60. ** 1 ] if [[ $match[2] == (h) ]] Delay=$[ $match[1] * 60. ** 2 ] if [[ $match[2] == (d) ]] Delay=$[ ($match[1] * 60. ** 2) * 24 ] if [[ $match[2] == (w) ]] Delay=$[ (($match[1] * 60. ** 2) * 24) * 7 ] : $(read -u 1 -t $Delay) else print -u 2 "Invalid delay time: $1" return 1 fi}To replace the system's "cat" command for standard input and output:
function zsh_cat { emulate -LR zsh zmodload zsh/system local buffer while sysread buffer do syswrite $buffer done}The zsh_cat function, in particular, is a good, basic example of what cannot be done in the popular bash/sh. Z Shell can do much more. Here are just a few more of Z Shell capabilities:
With all Zsh can do, it is worthy of being considered a language of its own, separate fromUNIX Shell but fully compatible. Though the executable for Zsh is much smaller than Bash, much of the extra capabilities, including Regex matching and new-user-detection load from modules and function autoload files. These numerous other files can be customized extensively, potentially creating system command/invocation incompatibilities. These can be overcome by using the standard option "-f", and by using the either the correct command name ("/bin/"(zsh|sh|ksh|bash)) or an emulation command ("emulate <shell> <shell-options>"). These features can ensure that the code written will be interpreted exactly how it is intended to be.