问题描述
我在Ubuntu终端中发出了一个命令,要求我键入yes,但是我发现它只在第一次问我,但是我在意识到之前已经按Enter键了。因此,我希望收到“找不到命令”消息,但是我得到了”y”s的never-ending流。这似乎是它唯一要做的事情,所以我想知道此命令的意义是什么,为什么它输出”y”s? (Ubuntu 11.10)
最佳回答
By itself, the yes command outputs ‘y’ or whatever is specified as an argument, followed by a newline repeatedly until stopped by the user or otherwise killed; when piped into a command, it will continue until the pipe breaks (i.e., the program completes its execution).
It can also be used to test how well a system handles high loads, as using yes results in 100% processor usage, for systems with a single processor (for a multiprocessor system, a process must be run for each processor). This, for example, can be useful for investigating whether a system’s cooling system will be effective when the processor is running at 100%.
次佳回答
很久以前(SySV天或更早),fsck
命令没有-y
或-n
选项。该命令将以交互方式要求您更改成百上千个项目,期望为’y’或’n’。创建yes
命令是为了将其传递给fsck,以及一些其他程序可以重复回答交互式问题(同样,这是SysV天,早于Tcl和Expect)。 yes
程序非常符合UNIX的哲学:小型程序可以很好地完成特定的任务并与其他程序一起工作。
第三种回答
根据此处提供的信息:http://linux.about.com/library/cmd/blcmdl1_yes.htm
Linux / Unix Command: yes
NAME
yes – output a string repeatedly until killed
SYNOPSIS
yes [STRING]… yes OPTION
DESCRIPTION
Repeatedly output a line with all specified STRING(s), or `y’.
–help display this help and exit –version output version information and exit
SEE ALSOThe full documentation for yes is maintained as a Texinfo manual. If the info and yes programs are properly installed at your site, the command
info yes
should give you access to the complete manual.
以我的拙见,当您必须通过按”y”键重复授权进程/脚本中的某些内容时,使用”yes”命令听起来很合逻辑。可以通过取消程序执行来控制。
无论如何,其他人可能有使用此命令的经验。