We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent a92582f commit a566c14Copy full SHA for a566c14
BashExample/eg_math.sh
@@ -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
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