Friday, 5 August 2011

Get input from keyboard and store to a variable.

-bash-3.00$  vi Din
echo "Enter The Number : "
read num
echo "Square of your number is `expr $num \* $num` "

bash-3.00$ chmod +x *
-bash-3.00$ ./Din
Enter The Number :
4
Square of your number is 16

Use of  bc command:-
-bash-3.00$ bc
scale=2
10 / 3
3.33
scale=5
10 / 3
3.33333


OR

-bash-3.00$ echo "scale=2" > myfile
-bash-3.00$ echo "5 / 2" >> myfile
-bash-3.00$ bc < myfile
2.50












No comments:

Post a Comment