# Zsh: parse command-line options with zparseopts

DevFeed: [Zsh: parse command-line options with zparseopts](<https://devfeed.tech/articles/zsh-parse-command-line-options-with-zparseopts-105876.md>)

Original publisher: [Read original article](<https://adamj.eu/tech/2026/10/28/zsh-zparseopts/>)

Author: Adam Johnson

Published: 2026-10-28T00:00:00Z

Content type: tutorial

Language: en

Sources: [Adam Johnson](<https://devfeed.tech/sources/adam-johnson.md>)

Topics: [Zsh](<https://devfeed.tech/topics/zsh.md>), [Shell](<https://devfeed.tech/topics/shell.md>), [Bash](<https://devfeed.tech/topics/bash.md>), [Command-line interface](<https://devfeed.tech/topics/cli.md>)

Tags: [argument](<https://devfeed.tech/tags/argument.md>), [arguments](<https://devfeed.tech/tags/arguments.md>), [array](<https://devfeed.tech/tags/array.md>), [bash](<https://devfeed.tech/tags/bash.md>), [code](<https://devfeed.tech/tags/code.md>), [command-line](<https://devfeed.tech/tags/command-line.md>), [compatibility](<https://devfeed.tech/tags/compatibility.md>), [function](<https://devfeed.tech/tags/function.md>), [git](<https://devfeed.tech/tags/git.md>), [help](<https://devfeed.tech/tags/help.md>), [options](<https://devfeed.tech/tags/options.md>), [scripts](<https://devfeed.tech/tags/scripts.md>), [shell](<https://devfeed.tech/tags/shell.md>), [zsh](<https://devfeed.tech/tags/zsh.md>)

## AI overview

Zsh's `zparseopts` handles short and long command-line options, including options with arguments, and stores parsed values in arrays. The excerpt's `caw` example uses `-D` to remove options from positional parameters, `-E` to allow options after positional arguments, and `-F` to reject unknown options or missing arguments; parsing errors can trigger a usage message, which must be maintained by hand. Options taking arguments use `:`, and repeated values can be read from the array (the example uses the last one); `+` makes an option accumulate. Unlike some command-line parsers, `zparseopts` does not treat `=` specially in `--number=3`, so the equals sign becomes part of the argument and must be stripped explicitly if that form is supported.

## Source excerpt

Sometimes you want your shell scripts to take options, like --verbose or --help, along with any positional arguments. Handling options is fiddly to do by hand, with the traditional portable approach being a large block of code using a while loop, a case statement, and some shifts. Bash has ...