Visit Jeremy's Blog.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 07-29-2010, 09:07 AM   #1
LQ Newbie
Registered: Jul 2010
Posts: 5

Rep: Reputation: 0
if condition

I am trying to compare two strings using the following code but it gives me error. I have tried couple of options but it does not work.
The code is

read -p "Do you want to continue ? Y/N - " opt
if ["$opt"== "N"];then
do something

and the error I get

./ line 20: [N==: command not found

I have tried this way as well

if [ $S1=$S2 ];

It still gives the same errror.

Any suggestions?

Old 07-29-2010, 09:11 AM   #2
Senior Member
Registered: Jan 2010
Posts: 1,617

Rep: Reputation: 450Reputation: 450Reputation: 450Reputation: 450Reputation: 450
Originally Posted by shashv2 View Post

read -p "Do you want to continue ? Y/N - " opt
if ["$opt"== "N"];then
do something

./ line 20: [N==: command not found
There has to be a space between [ and N. Also at the end of the expression between " and ].
if [  "$opt"== "N"   ];then
    do something
The '[' bracket is the same as the test command.
1 members found this post helpful.
Old 07-29-2010, 09:52 AM   #3
LQ Newbie
Registered: Jul 2010
Posts: 5

Original Poster
Rep: Reputation: 0
Thanks for the quick reply.

Last time (as in my previous thread) it gave an error due to space and in this case it gives error if there is a space.

The spaces in "IP = ..." could be the problem. When you initialise variables in Bash, you must not use spaces.

Your help is very much appreciated.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Or / And Condition in linux soumyacs Linux - Newbie 2 10-29-2009 10:39 AM
if condition furqan_sindhu Linux - Newbie 5 09-22-2007 06:56 AM
using OR condition in if condition Fond_of_Opensource Linux - Newbie 2 10-20-2006 12:34 AM
preg not condition dlublink Programming 5 05-31-2006 12:39 AM
cedega and CS: condition zero bojann Linux - Games 8 06-27-2005 01:49 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:30 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration