Re:Interesting commands for the Linux shell
by lozf on Friday September 15, 2017 @05:22AM
(#15255751)
Recently I needed results that included nothing after the decimal point, so resorted to awk to do the math:
awk "BEGIN { print int($SECONDS /60 /60)}"
Re:Interesting commands for the Linux shell
by vram22 on Friday September 15, 2017 @11:27AM
(#15257915)
Interesting. I suppose you had to type Ctrl-D or Ctrl-Z to signal no input to awk, since it expects some in the above command? Never tried running awk without either a filename as input or stdin coming from a file or a pipe. Will check it and see what happens.
Modifying my example from above:
echo "scale=0; $SECONDS / 60 / 60" | bc
might also work, need to check.
Re:Interesting commands for the Linux shell
by otherflavors on Saturday September 16, 2017 @03:51PM
(#15266390)
printf "%s 60 60 *2k/p" "$SECONDS" | dc
# will give 2 digits after the decimal point, instead of bc -l which gives more digits of precision after the decimal point, than we may usually want for this particular calculation.