Skip to content

Commit

Permalink
Create eg_math.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
XuhuaHuang committed Oct 30, 2021
1 parent a92582f commit a566c14
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions BashExample/eg_math.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/bash

# Commonly used commands with this file:
# bash --version
# cat eg_math.sh
# bash eg_math.sh

x=10
y=5

echo x=$x, y=$y
echo $x+$y=$((x+y))
echo $x-$y=$((x-y))
echo $x*$y=$((x*y))
echo $x/$y=$((x/y))

x=11
echo # print a empty line
echo 'New value for x'
echo x=$x, y=$y
# Perform division with Bash and bc
echo 'With Bash:' $((x/y))
echo -n 'With bc and scale set to 2: '
echo "scale=2; $x/$y" | bc

echo
echo -n 'Adding x and y with expression (expr): '
expr $x + $y
let "sum = $x + $y"
echo 'x + y =' $sum

0 comments on commit a566c14

Please sign in to comment.