script de shell “if” o teste não está funcionando como esperado [fechado]

0
#!/bin/bash

A="Message Agent is not buffering."
command > file
Buffering_status='/usr/xpg4/bin/awk -F '[()\t:-]' '{print $NF}' file|sed '/^$/d'|/usr/xpg4/bin/awk '{$1=$1}1'|uniq -u|tail -1'

agent_status_count='/usr/xpg4/bin/awk -F '[()\t:-]' '{print $NF}' file|sed '/^$/d'|/usr/xpg4/bin/awk '{$1=$1}1'|sed '$d'|sort -u|wc -l'
echo $Buffering_status $agent_status_count

if [[ $A == $Buffering_status  &&  $agent_status_count == 1 ]]
then

echo "executing fine part"

else

echo $Buffering_status $agent_status_count
echo "something wrong"

fi

Saída de depuração:

+ A='Message Agent is not buffering.'
+ command
++ /usr/xpg4/bin/awk -F '[()\t:-]' '{print $NF}' file
++ sed '/^$/d'
++ /usr/xpg4/bin/awk '{$1=$1}1'
++ uniq -u
++ tail -1
+ Buffering_status='Message Agent is not buffering.'
++ /usr/xpg4/bin/awk -F '[()\t:-]' '{print $NF}' file
++ sed '/^$/d'
++ /usr/xpg4/bin/awk '{$1=$1}1'
++ sed '$d'
++ sort -u
++ wc -l
+ agent_status_count='       1'
+ echo Message Agent is not buffering. 1
Message Agent is not buffering. 1
+ [[ Message Agent is not buffering. == Message Agent is not buffering. ]]
+ [[        1 == 1 ]]
+ echo Message Agent is not buffering. 1
Message Agent is not buffering. 1
+ echo 'something wrong'
something wrong
    
por Su_scriptingbee 18.08.2016 / 10:14

1 resposta

1

== é uma comparação de strings e, como kba apontou, "1" não é a mesma string que "1". O operador -eq fará o que você deseja.

...

if [[ $A == $Buffering_status  &&  $agent_status_count -eq 1 ]]

...

    
por 18.08.2016 / 15:23