#!/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 ]]
...