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
Problem with while loop in shell script rkrgarlapati Shell Programming and Scripting 20 02-02-2009 03:13 AM
Problem in for loop of shell scripting in solaris krevathi1912 SUN Solaris 12 12-03-2007 08:36 AM
Bourne-again shell mrsamer UNIX for Dummies Questions & Answers 3 09-30-2006 02:42 AM
for loop problem in K shell asutoshch Shell Programming and Scripting 4 09-06-2005 08:56 AM
Shell Script loop problem MaxMouse Shell Programming and Scripting 1 07-26-2005 03:19 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 09-18-2008
ahmad.diab's Avatar
ahmad.diab ahmad.diab is offline
Registered User
  
 

Join Date: May 2008
Location: Amman Jordan in MEA
Posts: 228
if loop problem in bourne shell

how to use if-loop in bourne shell with multiple conditions like follows

if [ a > b && c > d ]
then
commands
fi

it gives me an error

test: ] missing

then i put
if [[ a > b && c > d ]]
it gives me an error
[[ not found

kindly i need the syntex for the bourne shell
  #2 (permalink)  
Old 09-18-2008
avronius avronius is offline VIP Member  
VIP Member
  
 

Join Date: Apr 2008
Location: Calgary
Posts: 305
Have you tried
Code:
if [ a > b ] && [ c > d ]
  #3 (permalink)  
Old 09-18-2008
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,723
You must have an ancient version -
Code:
if [ $a -gt $b ] ; then
   if [ $c -gt $d ] ; then
   fi
fi
is what you will have to use.
  #4 (permalink)  
Old 09-18-2008
joeyg's Avatar
joeyg joeyg is offline Forum Staff  
modérateur
  
 

Join Date: Dec 2007
Location: Home of 17-time world champion Boston Celtics
Posts: 1,311
Cool Does the following example help you?

The first example executes to TRUE, and prints "greater". The second example is FALSE, and nothing prints

Code:
> if [ 14 -gt 13  -a  15 -gt 12 ] ; then echo "greater"; fi
greater

> if [ 4 -gt 13  -a  5 -gt 12 ] ; then echo "greater"; fi
  #5 (permalink)  
Old 09-18-2008
avronius avronius is offline VIP Member  
VIP Member
  
 

Join Date: Apr 2008
Location: Calgary
Posts: 305
Quote:
You must have an ancient version -
Seems I wasn't paying attention to the argument - just the format! Thanks Jim

This is what it could look like:
Code:
if [ $a -gt $b ] && [ $c -gt $d ]
  #6 (permalink)  
Old 09-20-2008
ahmad.diab's Avatar
ahmad.diab ahmad.diab is offline
Registered User
  
 

Join Date: May 2008
Location: Amman Jordan in MEA
Posts: 228
if loop problem in bourne shell

Thanks a lot guys , all the syntax worked fine except this one

if [ a > b ] && [ c > d ]

...thanks again
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 11:30 AM.


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