Answer the question
In order to leave comments, you need to log in
How to calculate square root in Linux terminal?
I am writing a script and I need to calculate the root of a number. What command can I do this?
Answer the question
In order to leave comments, you need to log in
Here is a useful snippet from my ~/.bashrc:
function round(){ [ "$2" = "" ] && NUM=3 || NUM=$2; echo $1 | sed "s/\(*\.\{,$NUM\}\).*/\1/"; }
function sin(){ echo "scale=10; s($1*a(1)/45);" | bc -l; }
function cos(){ echo "scale=10; c($1*a(1)/45);" | bc -l; }
function tan(){ echo "scale=10; arg=$1*a(1)/45; s(arg)/c(arg);" | bc -l; }
function logn(){ echo "scale=10; l($1);" | bc -l; }
function log(){ echo "scale=10; l($1)/l(10);" | bc -l; }
function pow(){ echo "scale=10; ($1)^($2);" | bc -l; }
function sqrt(){ echo "scale=10; sqrt($1);" | bc -l; }
function exp(){ echo "scale=10; e($1);" | bc -l; }
function bin2hex(){ echo "obase=16;ibase=2;$1" | bc; }
function bin2dec(){ echo "obase=10;ibase=2;$1" | bc; }
function dec2hex(){ echo "obase=16;ibase=10;$1" | bc; }
function lower(){ echo $1 | tr [:upper:] [:lower:]; }
function upper(){ echo $1 | tr [:lower:] [:upper:]; }
function hex2binary(){ echo "obase=2;ibase=16; $(upper $1)" | bc; }
function hex2dec(){ echo "obase=10;ibase=16; $(upper $1)" | bc; }
alias pi="echo 'scale=10; a(1)*4;' | bc -l"
export PI=$(pi)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question