Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
Define “no luck”. In meantime see if How to get execution time of a script effectively? has anything useful for you. – manatwork Oct 29 '12 at 9:37

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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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