-1
Hello I am trying to return 1 value for each variable I can return however, I am trying to create a condition that applies to one for which are true and which are false and display me on the screen could help me? below my code.
read numero
vartest1=`psql -X -A -d database -U usuario -h host1 -t -c "select telefone from tabela where numerodiscado = '$numero' limit 1;"`
vartest2=`psql -X -A -d database -U usuario -h host2 -t -c "select telefone from tabela where numerodiscado = '$numero' limit 1;"`
vartest3=`psql -X -A -d database -U usuario -h host3 -t -c "select telefone from tabela where numerodiscado = '$numero' limit 1;"`
vartest4=`psql -X -A -d database -U usuario -h host4 -t -c "select telefone from tabela where numerodiscado = '$numero' limit 1;"`
clear
ap1='t'
ap2='t'
ap3='t'
ap4='t'
for ((i=0; i<3; i++))
do
echo "${vetor[$i]}"
if [ $ap1 == "$vartest1" ]; then
echo "Telefone Localizado Ap1"
else
echo "Não Telefone Localizado Ap1"
sleep 1
if [ $ap2 == "vartest2" ]; then
echo "Telefone Localizado Ap2"
else
echo "Não Telefone Localizado Ap2"
if [ $ap3 == "vartest3" ]; then
echo "Telefone Localizado Ap3"
else
echo "Não Telefone Localizado Ap3"
if [ $ap4 == "vartest4" ]; then
echo "Telefone Localizado Ap4"
else
echo "Não Telefone Localizado Ap4"
fi
done
When executed, only the 1 condition is validated, in the case Ap1 is always true as it could make a chain of ifelse where it would validate independent of the position in the case compared to Ap1,Ap2,Ap3,ap4 if one of these were true return me on the screen, if all are false return me on the screen I’m not able to test all they could help me.
While is no longer easy to use
while [ condition ]
do
 command1
 command2
 command3
done
? that is, create two while conditions, one to check the true ones and one for the false ones. Or just a IF-ELSE, If true, echo true, If not echo false.– a_diogo
I managed to creating the while thank you very much.
– Victor