yes
Repeatedly output a string (default 'y')
TLDR
Repeatedly output "message"
Repeatedly output "y"
Accept everything prompted by the apt-get command
Repeatedly output a newline to always accept the default option of a prompt
SYNOPSIS
yes [STRING]...
yes OPTION
PARAMETERS
STRING...
The string to repeatedly output. If no string is specified, 'y' is used by default.
--help
Display help information and exit.
--version
Display version information and exit.
DESCRIPTION
The yes
command is a simple utility that repeatedly outputs a specified string, or 'y' by default, followed by a newline. It continues indefinitely until terminated manually (e.g., with Ctrl+C) or until the pipe it's writing to is closed. This behavior is particularly useful for automating responses to prompts in scripts or when interacting with commands that require confirmation inputs. For example, it can be piped to commands like rm -i
to automatically answer 'yes' to every confirmation prompt. While seemingly trivial, yes
is a valuable tool for scripting and automating tasks where user interaction needs to be bypassed. It helps prevent scripts from getting stuck waiting for user input and provides a way to predictably handle interactive commands in non-interactive environments. Note that using yes
indiscriminately can lead to unintended consequences, like deleting files you didn't intend to, so use it with caution.
CAVEATS
Using yes
without proper consideration can be dangerous. Piping it to commands that perform destructive operations without a clear understanding of the consequences can lead to data loss or system instability. It's also important to be aware that some programs may not respond as expected to a stream of 'y' inputs. Always test your scripts thoroughly before running them in a production environment.
EXAMPLES
yes | rm -i *.txt
This command pipes an endless stream of 'y' to the rm -i
command, which removes all .txt
files in the current directory after prompting for confirmation for each file. yes "hello world" | head -n 5
This command pipes an endless stream of 'hello world' to head
, which will output the string 'hello world' five times.yes no | command
This might cause an unexpected or undefined behavior, as yes
will print the strings sequentially. It could cause the command to exit prematurely depending on how the input is handled.
HISTORY
The yes
command has been a part of Unix-like operating systems for a very long time, likely dating back to the early days of Unix development. Its purpose was to automate interactive processes, a need that arose very early. It serves the simple, yet powerful, function of feeding input to commands that require user interaction, avoiding the need to manually type 'y' repeatedly. The utility has remained relatively unchanged over the years, reflecting its simple and effective design.