mardi 29 août 2017

if loop win while not working in shell script

I have a simple if else loop inside while but its not giving me a proper output needed. Please help #!/bin/bash

set -x
inputFile=/data2/example/output1.txt
while read col1 col2 col3; do
if [ $col2=='Success' ]
then
echo " This is Green"
else
echo " This is Red"
fi
done < ${inputFile}

Output am getting is:

+ read col1 col2 col3
+ '[' Success==Success ']'
+ echo ' This is Green'
 This is Green
+ read col1 col2 col3
+ '[' Success==Success ']'
+ echo ' This is Green'
 This is Green
+ read col1 col2 col3
+ '[' Failed==Success ']'
+ echo ' This is Green'

Here its not entering the else part and continuously displaying "This is Green".

Thanks for the help!

Aucun commentaire:

Enregistrer un commentaire