bash 如何在每个 xargs 命令之间休眠 1 秒?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15153240/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to sleep for 1 second between each xargs command?
提问by WDan
For example, if I execute
例如,如果我执行
ps aux | awk '{print }' | xargs -I {} echo {}
I want to let the shell sleep for 1 second between each echo.
我想让 shell 在每个echo.
How can I change my shell command?
如何更改我的 shell 命令?
回答by kamituel
You can use following syntax:
您可以使用以下语法:
ps aux | awk '{print }' | 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).
但是要小心空格和分号。在括号之间的每个命令之后,都需要分号(甚至在最后一个之后)。
回答by Basile Starynkevitch
Replace echoby some shell script named sleepechocontaining
替换echo为一些名为sleepecho包含的shell 脚本
#!/bin/sh
sleep 1
echo $*
回答by chepner
If your awksupports it:
如果您awk支持:
ps aux | awk '{ system("sleep 1"); print }' | xargs -I {} echo {}q
or skip awkand xargsaltogether
或跳过awk和xargs共
ps aux | while read -r user rest;
echo $user
sleep 1;
done

