如果循环获胜而不在shell脚本中工作

时间:2017-08-29 09:36:54

标签: unix if-statement

我在<VirtualHost *:443> ServerName extranet DocumentRoot /var/www/symfony2/extranet/web DirectoryIndex app.php Timeout 600 KeepAliveTimeout 67 SSLEngine on SSLCertificateFile /etc/apache2/ssl/extranet.crt SSLCertificateKeyFile /etc/apache2/ssl/extranet.key <Location /login_x509> SSLOptions +StdEnvVars SSLVerifyClient optional_no_ca SSLVerifyDepth 10 </Location> <Directory /var/www/symfony2/extranet/web> # enable the .htaccess rewrites AllowOverride All Order allow,deny Allow from All LimitRequestBody 1024000 </Directory> ErrorLog /var/log/apache2/extranet_error.log CustomLog /var/log/apache2/extranet_access.log combined </VirtualHost> 内部有一个简单的if else循环,但它没有给我正确的输出。

while

我得到的输出是:

#!/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}

此处未输入+ 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' 部分并持续显示else

2 个答案:

答案 0 :(得分:0)

这是一个小的语法错误:

if [ "$col2" == Success ]

这解决了我的问题。

答案 1 :(得分:0)

这是将变量与字符串进行比较的方式。使用此

"$col2" = "Success"

而不是

$col2 == 'Success'