winzsh Docs
WINZSH MANUAL

Commands and syntax

The winzsh prompt and scripts use the same syntax.

Starting winzsh

These examples use PowerShell in the folder where you extracted winzsh.

Command Behavior
.\winzsh.exe Starts interactively if both standard input and output are connected to a console. Otherwise, reads commands from standard input.
.\winzsh.exe --no-rc Skips the startup file when starting interactively.
.\winzsh.exe --version Prints the version and exits. In a running shell, use version instead.
.\winzsh.exe -c "pwd" Runs the specified command.
.\winzsh.exe .\example.wz Runs a UTF-8 script. The file can have any extension.

In non-interactive mode, winzsh does not load the startup file or display a prompt. When it reads commands from standard input, child commands see end-of-file on their own standard input by default. Use < or a pipe in the command line to give a child command input. With -c or a script file, child commands inherit standard input.

Built-in commands

Command Purpose
cd [DIR] Changes the working directory. Without an argument, goes home. cd - goes to the previous working directory and prints its full path.
pushd [DIR] Saves the current directory on the stack and changes directories. Without an argument, swaps the current directory with the top of the stack.
popd Returns to the directory on top of the stack and removes it from the stack.
dirs [-p|-c] Prints full paths, starting with the current directory and then the directory you would return to first. -p prints one entry per line; -c clears the stack without changing directories.
pwd Prints the current working directory.
ls [PATH...] Lists directory contents or displays the specified entries.
mkdir [-p] [--] DIR... Creates directories. -p creates missing parents and leaves existing directories in place.
cp [-r] [--] SRC... DEST Copies files. Copying directories, even empty ones, requires -r or -R.
mv [--] SRC... DEST Moves or renames files and directories within the same volume.
touch [-c] [--] PATH... Sets access and modification times to the current time without truncating files. Creates empty files if missing, unless -c is given.
rm [-rf] [--] PATH... Deletes files. Use -r or -R to delete directory trees. -f ignores missing entries.
rmdir [--] DIR... Deletes empty directories.
cat [--] [FILE...] Writes the contents of files in order, including binary files.
head [-n N] [--] [FILE] Prints the first N lines. N is a nonnegative integer and defaults to 10.
tail [-n N] [--] [FILE] Prints the last N lines (10 by default). Follow mode (-f) is not supported.
which COMMAND... Shows how each command name resolves.
echo [ARG...] Prints its arguments.
alias [NAME=VALUE...] Lists or sets aliases.
unalias [--] NAME... / unalias -a Removes the specified aliases (or all aliases with -a). An undefined name is reported as an error, but the remaining names are still processed.
export [NAME=VALUE...] Lists or sets environment variables.
unset [--] [NAME...] Removes environment variables rather than setting them to empty strings. Names are case-insensitive, and undefined names are ignored. For example, unset PROMPT_COMMAND disables the dynamic prompt.
source FILE Runs a UTF-8 file in the current shell. For example, source "$USERPROFILE\.winzshrc" reloads your settings.
clear Clears the visible console and moves the cursor to the upper left. Writes nothing when output goes to a file or pipe.
version Prints the running shell's version as winzsh <version>.
exit [STATUS] Exits the shell with the given exit status.

Run cd - repeatedly to switch between two directories. It also works immediately after moving with pushd or popd. If there is no previous directory or it no longer exists, the command reports an error without changing the current directory. Use cd .\- to enter a directory named -.

Use pushd "C:\Program Files" to visit a directory temporarily, then popd to return. Both commands print the same listing as dirs when successful. Ordinary cd does not add to the stack. If the destination no longer exists, the command reports an error without changing the current directory or the stack. Numeric stack rotation is not supported. Use pushd -- NAME for a directory name starting with - or +.

mkdir src tests creates two directories in the current directory. Use mkdir -p "work area\logs" to create a whole path, and mkdir -- -logs for a name starting with -. Without -p, a destination that already exists or has a missing parent is an error. If you give multiple destinations, mkdir continues with the rest after an error.

Use cp "original notes.txt" copy.txt to make a copy, then mv copy.txt archive.txt to rename it. To copy several files with cp a.txt b.txt archive, first create the destination with mkdir archive. A destination ending in \ or / must be an existing directory. Copying or moving does not overwrite files, merge trees, copy a file onto itself, copy a tree into itself, or transfer reparse points such as junctions. An I/O error during a copy can leave partial output. mv fails across volumes and leaves the source in place.

rm deletes entries without sending them to the Recycle Bin. It removes a junction without deleting the target contents, and rm -r does not follow links inside the tree. You cannot remove a root directory, the current directory, its ancestors, or a path ending in . or ... Access errors still cause rm -f to fail. touch reports an error rather than changing the timestamps of a reparse point.

Work without external tools

mkdir work
cd work
touch notes
echo TODO: Review > notes
echo Done >> notes
cp notes copy
mv copy log
cat log | head -n 1
tail -n 1 log
rm notes log
cd ..
rmdir work

cat, head, and tail read from standard input when you omit the filename or pass -. In interactive mode, press Ctrl+C to stop a command waiting for input. These commands do not change line endings or add a final newline. Use different files for input and output: > truncates the output file before the command runs.

Writing paths and variables

Use ordinary Windows notation for drive letters and UNC paths. Quote arguments that contain spaces. Double quotes expand variables; single quotes keep them literal.

cd "C:\Program Files"
export LABEL="work folder"
echo "$LABEL"
echo '$LABEL'

The first echo prints work folder, and the second prints $LABEL. You can also write the variable as ${LABEL}. Expanded values are not split on whitespace or reparsed as shell syntax.

Script syntax errors include the filename and line number, for example settings.wz:3: syntax: unclosed quote. The shell skips that line and continues with the next one. Errors inside source refer to the file being read. A read error, such as a line that is not valid UTF-8, stops execution of that input.

Finding external commands

Use which where.exe to see the path of the file that will run. When you pass only a command name, winzsh checks the directories in PATH in order. If you omit the extension, it tries the extensions in PATHEXT order within each directory.

To run grep with Git for Windows installed in its default location, you can use "C:\Program Files\Git\usr\bin\grep.exe" -n TODO notes without starting Bash or changing PATH.

Connecting commands

| connects the standard output of the command on the left to the standard input of the command on the right. This example filters the list of running processes for lines containing explorer.exe.

tasklist.exe | findstr.exe /i explorer.exe

Pipes between external commands pass bytes unchanged. The exit status of a pipeline is the exit status of its last command.

Syntax Behavior
cmd < input.bin Reads standard input from a file.
cmd > out.txt / cmd >> out.txt Overwrites a file with standard output or appends to it.
cmd 2> err.txt / cmd 2>> err.txt Overwrites a file with standard error or appends to it.
a && b / a || b Runs b only if a succeeds or fails, respectively.
a; b Runs b after a.