0

I need help using time in the c-shell I want to know how much time it took to execute a script,so i want to do in the following way

1.set start_time=time
2 script part
3.set end_time=time
4. set diff=end_time-start_time
5.echo "It took $diff seconds"

but i couldn't get the time value using any command.
could any one suggest a command to read the time value in c-shell

Lance Richardson
  • 4,610
  • 23
  • 30
Vinod kumar
  • 67
  • 1
  • 11
  • Why don't you just use `time ./script.sh` ? – fedorqui Feb 25 '14 at 15:28
  • script is not shell script. it is c-shell and i want to do it in the makefiles. i cant run bash commends in c-shell once i do csh commnad – Vinod kumar Feb 25 '14 at 15:32
  • Well but in general, you can use `time` in front of any command to see how long does it take to complete. – fedorqui Feb 25 '14 at 15:33
  • No.. Actually what happens is.. i don't require the whole time taken by a script but i need b/w few commands which takes much time – Vinod kumar Feb 25 '14 at 15:36
  • By the way time command is giving real,usr,sys like that ..is there a way to format it to get seconds or hours in normal time – Vinod kumar Feb 25 '14 at 15:39

1 Answers1

1

I think you want the "date" command, with the format to give you raw seconds:

@ start_time = `date +%s`
script part
@ end_time = `date +%s`
@ diff = $end_time - $start_time
echo "It took $diff seconds"
Mark Armstrong
  • 440
  • 1
  • 3
  • 11