I would like to parse ports, for instance 45:68. I defined testing var.
echo "ports"
read in
I splited ports to array:
IFS=":" read -ra port <<< "$in"
Ports must be less than 65535, contain only numbers and must be filled out. So I set while loop based on mentioned conditions.
while [ -z "${port[@]}" ] || [[ "${port[0]}" =~ ^-?[0-9]+$ ]] || [[ "${port[1]}" =~ ^-?[0-9]+$ ]] ||[ "${port[@]}" -gt 65535 ]
do
port=$(whiptail --title "No!" --inputbox --nocancel "Error MSG." 12 50 3>&1 1>&2 2>&3)
done
After I had executed my script I got stucked in loop.
Is there some better way to parse ports successfully?
whileloop will continue forever while a condition exists. You might want to consider aforloop that will iterate over each array element in turn.