0

I want to save the output of the find command in $path variable, and save the execution time of this command in t variable.
something like this, but its incorrect.

t=`time path=`find . -type d  -iname "$x"` `

the blow command works well, but this is in the loop and I want to have the sum of the time in a variable

time path=`find . -type d  -iname "$x"`
1
  • 3
    Don't use backticks, use $() Commented Jan 12, 2016 at 10:11

1 Answer 1

1

You can use a temporary file and GNU time:

TMPFILE="$(mktemp)"
path="$( /usr/bin/time -o "$TMPFILE" find . -type d  -iname "$x" )"
t="$(cat "$TMPFILE")"
rm -f "$TMPFILE"

For higher security, you can also use a temporary directory etc.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.