time take by a script

Hi !

I have got a script which takes some time to execute.
Eg. if the script is called test.sh

#!/bin/bash
<command1 to execute>
<command2 to execute>
<command3 to execute>
<command4 to execute>
.
.
.
.
<command n to execute>

At the end of the script I want to show the users the actual time(user NOT CPU) taken for the script to execute. I know of the time
command but where shall I put in the code for calculating the time.

Hi..

A solution would be to use test.sh to time another shell script with the acctual commands..
---
test.sh
#!/bin/sh
time /path/to/script/sh

---

/Peter

#!/bin/ksh

time ( command1 && \
           command2 && \
           command3 && \
           commandn )

exit 0

For some reason this won't work with bash nor sh. It works fine and dandy with ksh though.

Peter's solution above is guaranteed to work on all shells so is the solution I'd personally go for.

Ta,
ZB

Thanks Peter!

I was expecting a similar solution.:slight_smile:

Cheers