gpt4 book ai didi

linux - 将命令的输出和执行时间保存在 bash 脚本中的不同变量中

转载 作者:太空宇宙 更新时间:2023-11-04 10:41:54 24 4
gpt4 key购买 nike

我想把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"

为了更高的安全性,您还可以使用临时目录等。

关于linux - 将命令的输出和执行时间保存在 bash 脚本中的不同变量中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34739836/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com