I have the following program where I want to print a variable $var
that I fill with the execution time of a program. However, when outputting it to the console with echo
or printf
the value is empty.
Program:
#!/bin/bash
for n in 1 2 3 4;
do my_time="$(time var=$(echo "scale=100; 4*a(1)" | bc -l))";
echo $var
echo $my_time
printf "Value of PI is :%s\n" $var
done
Output:
real 0m0.003s
user 0m0.000s
sys 0m0.000s
Value of PI is :
real 0m0.004s
user 0m0.000s
sys 0m0.000s
Value of PI is :
real 0m0.004s
user 0m0.000s
sys 0m0.000s
Value of PI is :
real 0m0.004s
user 0m0.000s
sys 0m0.000s
Value of PI is :
Where is the problem, and how to solve it?