-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a92582f
commit a566c14
Showing
1 changed file
with
30 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |