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?

1
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.