-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcalc
More file actions
executable file
·31 lines (28 loc) · 881 Bytes
/
calc
File metadata and controls
executable file
·31 lines (28 loc) · 881 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/bin/bash
help() {
echo "Usage: calc expression"
echo "Use awk for arithemetic operations"
echo
echo "Operations: "
echo
echo " x + y Addition"
echo " x - y Subtraction"
echo " - x Negation"
echo " x * y Multiplication"
echo " x / y Division"
echo " x % y Modulo"
echo " x ^ y Exponentiation"
echo " int(x) Truncate integer toward zero"
echo " sqrt(x) Positive square root"
echo " exp(x) Exponentiation e ^ x"
echo " log(x) Natural logarithm"
echo " sin(x) Sine (in radians)"
echo " cos(x) Cosine (in radians)"
echo " atan2(x, y) Arctangent of x / y (in radians)"
echo " rand() Random number between zero and one"
echo " srand(x) Random number starting at x"
echo
exit 1
}
[ "$1" == "--help" ] && help
awk "BEGIN{print $1}"