LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices

Reply
 
Search this Thread
Old 07-29-2010, 09:07 AM   #1
shashv2
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
fi


and the error I get


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

I have tried this way as well

#!/bin/bash
S1='string'
S2='String'
if [ $S1=$S2 ];


It still gives the same errror.

Any suggestions?

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

Rep: Reputation: 446Reputation: 446Reputation: 446Reputation: 446Reputation: 446
Quote:
Originally Posted by shashv2 View Post

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

./newtest.sh: line 20: [N==: command not found
There has to be a space between [ and N. Also at the end of the expression between " and ].
Code:
if [  "$opt"== "N"   ];then
    do something
fi
The '[' bracket is the same as the test command.
 
1 members found this post helpful.
Old 07-29-2010, 09:52 AM   #3
shashv2
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.
 
  


Reply


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


All times are GMT -5. The time now is 04:57 PM.

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