The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
if statement ramky79 Shell Programming and Scripting 6 05-29-2008 03:17 AM
IF Statement koti_rama Shell Programming and Scripting 3 04-29-2008 04:48 AM
If statement - How to write a null statement april Shell Programming and Scripting 3 04-16-2008 01:14 PM
IF statement on a df -g hassanj UNIX for Advanced & Expert Users 1 12-18-2007 07:41 AM
If statement mariner UNIX for Advanced & Expert Users 4 12-16-2004 07:21 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 02-01-2008
jisha jisha is offline
Registered User
  
 

Join Date: Jan 2008
Location: Bangalore,India
Posts: 144
Arrow using && in if statement ..

Hi All,

Can some one tell me how to get run the following:

data1="hello"
data2="world"
if [ "$data2" != "world" && "$data1" != "hello"]
then
{
echo "good afternnon"
}
else
{
echo " good morning"
}
fi


The above code gives me an error ad below :
./if.h: line 3: [: missing `]'

Thanks in advance
Js
  #2 (permalink)  
Old 02-01-2008
panknil panknil is offline
Registered User
  
 

Join Date: Apr 2007
Location: Kolkata
Posts: 83
Thumbs up

Dear jisha,

try this

data1="hello"
data2="world"
if [ "$data2" != "world" ]
then
if [ "$data1" != "hello" ]
then
echo "good afternnon"
fi
else

echo " good morning"
fi

Regards,
Pankaj
  #3 (permalink)  
Old 02-01-2008
Tytalus's Avatar
Tytalus Tytalus is offline Forum Advisor  
echo {1..9}^2\;|bc
  
 

Join Date: Jun 2003
Location: Scotland
Posts: 431
try:

Code:
if [ "$data2" != "world" ] && [ "$data1" != "hello" ]
  #4 (permalink)  
Old 02-01-2008
V3l0 V3l0 is offline
Registered User
  
 

Join Date: Nov 2007
Location: Belgium & France
Posts: 70
Don't forget to let a space before ] and after [ !
Here is the code :
Code:
data1="hello"
data2="world"
if [ "$data2" != "world" ] && [ "$data1" != "hello" ]
then
{
        echo "good afternnon"
}
else
{
        echo " good morning"
}
fi
  #5 (permalink)  
Old 02-01-2008
manas_ranjan's Avatar
manas_ranjan manas_ranjan is offline
Registered User
  
 

Join Date: Jul 2007
Location: Amsterdam
Posts: 177
which code is this ???? shell script ?????
  #6 (permalink)  
Old 02-01-2008
jisha jisha is offline
Registered User
  
 

Join Date: Jan 2008
Location: Bangalore,India
Posts: 144
Thanks to all !!

Its working now.. I did a lot of debugging still i didnot get ...I think the problem was with the spacing

Thank you so much

Js
  #7 (permalink)  
Old 02-01-2008
fpmurphy's Avatar
fpmurphy fpmurphy is online now Forum Staff  
Moderator
  
 

Join Date: Dec 2003
Location: Florida
Posts: 1,912
If you want to make your schell script more efficient you should use the shell builtins

Code:
#!/usr/bin/ksh

data1="hello"
data2="world"

if [[ "$data2" != "world" && "$data1" != "hello" ]]
then
    print "good afternnon"
else
    print "good morning"
fi
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 09:13 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0