delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2009/10/27/15:07:18

X-Recipient: archive-cygwin AT delorie DOT com
X-SWARE-Spam-Status: No, hits=-2.2 required=5.0 tests=AWL,BAYES_00
X-Spam-Check-By: sourceware.org
MIME-Version: 1.0
Subject: RE: Bash - IF Statement
Date: Tue, 27 Oct 2009 15:07:04 -0500
Message-ID: <786EBDA1AC46254B813E200779E7AD365C3EEA@srv1163ex1.flightsafety.com>
In-Reply-To: <26084169.post@talk.nabble.com>
References: <26084169 DOT post AT talk DOT nabble DOT com>
From: "Thrall, Bryan" <bryan DOT thrall AT flightsafety DOT com>
To: <cygwin AT cygwin DOT com>
X-IsSubscribed: yes
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Unsubscribe: <mailto:cygwin-unsubscribe-archive-cygwin=delorie DOT com AT cygwin DOT com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com

briglass111 wrote on Tuesday, October 27, 2009 3:02 PM:

> I am trying to write an IF Statement in Bash, but I am having issues.
It
> doesn't like the following format:
>=20
> echo "yes or no?"
> read T
>=20
> if ["$T"=3D"y"];
> then
>         echo "YES"
> fi
>=20
> .............. It also doesn't like the following alternatives:
>=20
> if [$T=3D"y"];
> if ["$T"=3D=3D"y"];
> if [$T=3D=3D"y"];
> if "$T"=3D"y";
> if [["$T"=3D"y"]];
>=20
> etc..
>=20
> It says:
> y=3Dy: command not found
>=20
> Ideas?

You need to add some whitespace so bash can distinguish commands and
arguments:

$ if [ "$T" =3D "y" ];
then
  echo "YES";
fi
YES

BTW, this is not a Cygwin-specific question :)
--=20
Bryan Thrall
FlightSafety International
bryan DOT thrall AT flightsafety DOT com

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019