Forrest logo
back to the choice tool

choice:tldr:0162c

choice: Prompt the current user to select a `Y` or `N` choice.
$ choice
try on your machine

The "choice" command is a Windows command prompt command used to prompt the user to select from a list of options. It displays a message with a specified set of options and waits for the user to input a choice. Once the user selects an option, the chosen option's index value is returned by the command.

The syntax for the choice command is as follows:

choice [/c options] [/n] [/t timeout] [/d default] [/m message]

Here are the available options for customizing the behavior of the command:

  • /c options: Defines the set of options for the prompt. The options must be a string of characters enclosed in double quotation marks (""). For example, /c "yn" specifies the options "y" and "n".

  • /n: Used to bypass the prompt and immediately return the default choice. This is helpful when automating a script that does not require user interaction.

  • /t timeout: Sets the timeout period, in seconds, before the default option is selected if the user does not provide any input. For example, /t 10 sets a 10-second timeout.

  • /d default: Specifies the default choice if the user does not provide any input before the timeout. The default option must be included in the set of options defined by /c.

  • /m message: Defines the prompt message displayed to the user. The message must be enclosed in double quotation marks ("").

Once the user selects an option, the chosen option's index value (1-based) is stored in the ERRORLEVEL environment variable. This allows you to use conditional statements or scripts to perform different actions based on the selected option.

This explanation was created by an AI. In most cases those are correct. But please always be careful and never run a command you are not sure if it is safe.
back to the choice tool