[英]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.