3

I have to run a couple of command lines on a shell script on Ubuntu, one of those is a pi calculation.

It works fine when i run it on terminal via the following cmd line:

time echo "scale=6500;4*a(1)" | bc -l

But when I run it on a script I get no luck. Typing in time before I execute the script i.e.

time ./filename.sh

isn't enough as I have to also run other commands in the script.

Any suggestions?

Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
Conrad
  • 31
  • 1
  • 1
    Define “no luck”. In meantime see if [How to get execution time of a script effectively?](http://unix.stackexchange.com/questions/52313/how-to-get-execution-time-of-a-script-effectively) has anything useful for you. – manatwork Oct 29 '12 at 09:37

1 Answers1

4

I suspect your interactive shell is bash or zsh where time is a keyword.

And your script is a sh script (where sh is not based on bash, ksh nor zsh) where time is /usr/bin/time which would only time the echo command above.

Just do:

echo ... | "time" bc ...

as it's really bc you want to get the execution time of here.

Quoting time here makes sure it's not treated as a keyword in shells that have a time keyword.

Stéphane Chazelas
  • 522,931
  • 91
  • 1,010
  • 1,501