这个StackOverflow问题提到了一个名为“repeat”的unix命令。 这听起来像它正是我想要的。 从阅读问题和答案,我认为用户在Mac OSX上。
然而这个命令在Ubuntu上默认没有安装,我找不到要安装的软件包。 我应该安装什么?
我在Ubuntu上找不到这个命令。 它似乎并不存在。 我甚至觉得很奇怪,StackOverflow上的post说这是一个内置的命令,当我在Ubuntu上找不到它。
编辑:像马特指出的,这是一个内置的csh命令。 以下是与bash完全相同的提示。
如果你想要重复一个命令n次,你可以用一个循环来做到这一点:
for i in {1..n}; do yourcommand; done
例如,要打印100次“It works”,请使用:
for i in {1..100}; do echo "It works"; done
如果你想有一个repeat函数,你可以在你的~/.bashrc添加这样的内容:
function repeat() { local times="$1"; shift; local cmd="$@"; for ((i = 1; i <= $times; i++ )); do eval "$cmd"; done }
再次使用~/.bashrc . ~/.bashrc . ~/.bashrc ,你可以调用它:
$ repeat 2 date Mon Dec 21 14:25:50 CET 2009 Mon Dec 21 14:25:50 CET 2009 $ repeat 3 echo "my name is $USER" my name is raphink my name is raphink my name is raphink
您可以使用watch,这是任何shell中的标准命令。 例如:
watch -n 5 date
从提示,我想这是一个csh内build。
从阅读“man csh”看来,情况就是如此
repeat count command The specified command, which is subject to the same restric- tions as the command in the one line if statement above, is executed count times. I/O redirections occur exactly once, even if count is 0.
所以为了使用它,可以input“csh”并从命令行发出,或者编写你的脚本,使它使用#!/ bin / csh作为顶层的解释器。 这里有一些基本的csh让你开始。