mercredi 10 juin 2020

What is wrong in this if condition?

This is my code

ports="161,123"
portsArr=$(echo "${ports}" | tr "," "\n")
for port in "${portsArr[@]}"
do
    echo "${port}"

    if [ "${port}" = "161" ]; then
        echo "161";
    fi

    if [ "${port}" = "123" ]; then
        echo "123";
    fi
done

For some reason, the if conditions in this code is not working. Although, I'm getting expected results in the Line 5 echo command. Can somebody please explain what is wrong here?

Aucun commentaire:

Enregistrer un commentaire