Shellscript for returning bank values each value in 1 different variable?

Asked

Viewed 39 times

-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 ]&#xA;do&#xA; command1&#xA; command2&#xA; command3&#xA;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.

  • I managed to creating the while thank you very much.

2 answers

0

It’s easier to use While: while [ condition ] do command1 command2 command3 done that is, create two conditions while, one to verify the true ones and the other for the false ones. Or so just an IF-ELSE, If true, echo verdadeiras, Otherwise echo falsa.

0


After researching and making enough mistakes I managed to create a while that meets my need.

while [[ "$vrx" == "$num5"  ]] || [[ "$vrx" == "$num6" ]] 
do
if [ $vrx == $num5 ]; then
  echo "Telefone $numero  - Status: Está Inativo"
  sleep 1
  ativa
elif [ $vrx == $num6 ]; then
  echo "Telefone $numero - Status: Está Ativo"
  sleep 1
  ativa
else
   echo "Telefone não Encontrado"
  sleep 1
  aclp
fi
done

Thanks to all of the stack for the help.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.