Bash #5 - calculating with arithmetic operations & numbers (integers)

Опубликовано: 22 Февраль 2026
на канале: itvraag
749
11

In this video we cover doing simple math/calculations in bash using integers (whole numbers) and variables. Variables were covered in the previous video. We use mostly brackets for calculations, due it's simplicity, but you can also use other commands like, let, bc, declare, printf and awk.
#terminal #bash #bashscripting #linux
https://itvraag.nl

Timestamp:
0:00 Intro
0:16 bash challenge #2 answer
0:53 bash commands for calculation
1:23 using brackets
2:06 math with variables
2:47 increment or decrement
3:15 calculate with multiple variables
3:35 calculate using let command
3:44 calculate date
4:09 bash challenge #3

Relevant videos:
Bash #4 - variables:    • Bash #4 - working with variables (with cha...  
Bash #3 - script files:    • Bash #3 - Script files (with challenge)  
Bash #2 - help, touch, echo & aliases:    • Bash #2 - Help, touch, echo & aliases  
Bash #1 - basic concepts:    • Bash #1 - Basic concepts and requirements ...  

Used links and commands:
echo $((2+2))
echo $((4-11))
echo $((3*2))
echo $((18/3))
echo $((1/3))
echo $((2/3))
echo $(( (8*2) / (5-1) ))
x=22
((x++))
echo $((x--))
((x/=2))
echo $((x=44,x/=4))
x=$((x+2))
x=22;y=3
((a=x*y,b=a+11))
echo $x $y $a $b
echo $((x=22,y=3,a=x*y,b=a+11))
newDate=$(date -d "+10 days")
echo $newDate

Arithmetic Operator Description
*, /, % multiplication, division, remainder
+, - addition, subtraction
id++, id– post-increment & -decrement
++id, –id pre-increment & -decrement
==, != equality, inequality
& AND
| OR
&& logical AND
|| logical OR