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?

Conrad
  • 31
  • 1

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.