Linux yes command (reproduced)

yes command:
     The yes command repeatedly outputs the given string until it is terminated, separated by spaces, followed by a line character. If no string is specified, it repeatedly outputs 'y' until it terminates. It is typically used in scripts where confirmation prompts and questions for commands and programs can be piped and questions answered (eg: are you sure you want to delete this file, press 'y' or 'n').
Syntax:
The   syntax is
yes [string..]
     yes [command switch..]
command switch:

--help
Display help information and exit.

--version
Display version information and exit.

 

Example:

  1. Repeat the output of the following string:
    yes "hscripts"

    The above command will repeatedly display hscripts until the hotkey is pressed to terminate it (CTRL+C).

  2. When deleting a file requires confirmation, delete the file without pressing a key:
    yes | rm -i *.txt

    In the above example, the yes command is run with the rm command pipeline. Usually the rm -i command prompts you to delete the file, you must type y (yes) or n (no) to delete the file. When run in a pipeline with yes, the default value of yes will show yes and all files that will be automatically deleted, so you don't need to type y on every txt file to delete it.

    yes n | rm -i *.txt
    In the above example, when rm -i confirms to delete the file, typing n means not to delete the file. 

Original address: http://www.cnblogs.com/yuallen/archive/2010/05/12/1733397.html

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326920576&siteId=291194637
Recommended