[英]save output and execution time of command in diffrent variables in bash script
我想将find命令的输出保存在$ path变量中,并将此命令的执行时间保存在t变量中。
像这样的东西,但是它是不正确的。
t=`time path=`find . -type d -iname "$x"` `
blow命令效果很好,但这在循环中,我想将时间总和包含在变量中
time path=`find . -type d -iname "$x"`
您可以使用一个临时文件和GNU时间:
TMPFILE="$(mktemp)"
path="$( /usr/bin/time -o "$TMPFILE" find . -type d -iname "$x" )"
t="$(cat "$TMPFILE")"
rm -f "$TMPFILE"
为了提高安全性,您还可以使用临时目录等。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.