Bash #14 - while / until loops (with port scan example)

Опубликовано: 18 Апрель 2026
на канале: itvraag
334
8

In this video we'll go through while and until loops in bash scripting and test this using examples like a port scan.
#bashscripting #terminal
https://itvraag.nl

Related videos:
Bash #1 - Basics:    • Bash #1 - Basic concepts and requirements ...  
Bash #3 - Script files:    • Bash #3 - Script files (with challenge)  
Bash #4 - Variables:    • Bash #4 - working with variables (with cha...  
Bash #5 - Arithmetic operators:    • Bash #5 - calculating with arithmetic oper...  
Bash #10 - Combining commands:    • Bash #10 - Combining commands (skip waiting)  

Used scripts:
#!/bin/bash
n=0
while [ $n -lt 9 ]
do
echo This number is less than 9: $n
((n++))
done

#!/bin/bash
n=0
until [ $n -gt 9 ]
do
echo This number is NOT greater than 9: $n
((n++))
done

#!/bin/bash
n=0
i=12
while [[ $n -lt 9 && i -lt 14 ]]
do
echo This number $n is less than 9 and this number $i is less than 14
((n++))
((i++))
done

Port scan script (angled brackets are removed, due to video description limitations):
#!/bin/bash
i=0
while [ $i -lt 5000 ]
do
(echo /dev/tcp/127.0.0.1/$i) &/dev/null && printf "Open Port at:$i" || printf "."
((++i))
done

Timestamp:
0:27 while & until loops in general
0:43 while loop with example
1:01 logical conditions
1:34 until loop with example
1:47 loops with multiple conditions
2:25 while loop with port scan
2:58 endless loops