Skip to content

Commit a566c14

Browse files
committed
Create eg_math.sh
1 parent a92582f commit a566c14

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

BashExample/eg_math.sh

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/bin/bash
2+
3+
# Commonly used commands with this file:
4+
# bash --version
5+
# cat eg_math.sh
6+
# bash eg_math.sh
7+
8+
x=10
9+
y=5
10+
11+
echo x=$x, y=$y
12+
echo $x+$y=$((x+y))
13+
echo $x-$y=$((x-y))
14+
echo $x*$y=$((x*y))
15+
echo $x/$y=$((x/y))
16+
17+
x=11
18+
echo # print a empty line
19+
echo 'New value for x'
20+
echo x=$x, y=$y
21+
# Perform division with Bash and bc
22+
echo 'With Bash:' $((x/y))
23+
echo -n 'With bc and scale set to 2: '
24+
echo "scale=2; $x/$y" | bc
25+
26+
echo
27+
echo -n 'Adding x and y with expression (expr): '
28+
expr $x + $y
29+
let "sum = $x + $y"
30+
echo 'x + y =' $sum

0 commit comments

Comments
 (0)