쉘 스크립트 "if" 테스트가 예상대로 작동하지 않습니다.

쉘 스크립트 "if" 테스트가 예상대로 작동하지 않습니다.
#!/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

디버그 출력:

+ 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

답변1

==이는 문자열 비교이며 kba가 지적했듯이 "1"과 "1"은 동일한 문자열이 아닙니다. 교환원이 -eq원하는 대로 해줄 것입니다.

...

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

...

관련 정보