阅读背景:

如何在每个xargs命令之间睡眠1秒?

来源:互联网 

For example, if I execute

例如,如果我执行

ps aux | awk '{print 

For example, if I execute

例如,如果我执行

ps aux | awk '{print $1}' | xargs -I {} echo {}

I want to let the shell sleep for 1 second between each echo.

我想让壳层在每次回波之间休眠1秒。

How can I change my shell command?

如何更改shell命令?

3 个解决方案

#1


30  

You can use following syntax:

您可以使用以下语法:

ps aux | awk '{print $1}' | xargs -I % sh -c '{ echo %; sleep 1; }'

Be careful with spaces and semicolons though. After every command between brackets, semicolon is required (even after last one).

注意空格和分号。在括号之间的每个命令之后,都需要分号(甚至在最后一个命令之后)。

#2


0  

Replace echo by some shell script named sleepecho containing

用一个名为sleepecho的shell脚本替换echo

 #!/bin/sh
 sleep 1
 echo $*

#3


0  

If your awk supports it:

如果您的awk支持:

ps aux | awk '{ system("sleep 1"); print $1 }' | xargs -I {} echo {}q

or skip awk and xargs altogether

或者干脆跳过awk和xargs

ps aux | while read -r user rest;
    echo $user
    sleep 1;
done

}' | xargs -I {} echo {} ps aux



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: