3 Replies - 1091 Views - Last Post: 18 July 2011 - 10:17 PM Rate Topic: -----

#1 j_akins   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 09-April 09

Using ** in Bash compound condition testing

Posted 18 July 2011 - 09:44 PM

Can someone please shed some light on why the following will not work in BASH. I'm trying this on Linux.

if (( $RESULT -ge 1024**2 )) && (( $RESULT -lt 1024**3 ))
then
      do something......
fi




RESULT represents the size of an object in bytes..
Is This A Good Question/Topic? 0
  • +

Replies To: Using ** in Bash compound condition testing

#2 no2pencil   User is online

  • Professor Snuggly Pants
  • member icon

Reputation: 6824
  • View blog
  • Posts: 31,471
  • Joined: 10-May 07

Re: Using ** in Bash compound condition testing

Posted 18 July 2011 - 09:57 PM

For one, the brackets on your if statement are wrong, & for two, why are you using two asterisks?

#!/bin/sh

RESULT=2049

if [[ $RESULT -ge 1024*2 ]] && [[ $RESULT -lt 1024*3 ]]
then
  echo wee!
fi



This outputs wee! when executed.
Was This Post Helpful? 0
  • +
  • -

#3 j_akins   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 09-April 09

Re: Using ** in Bash compound condition testing

Posted 18 July 2011 - 10:12 PM

I thought you use the [[]] for strings only. The ** are exponent operator. I'm not trying to multiply 1024...
Was This Post Helpful? 0
  • +
  • -

#4 no2pencil   User is online

  • Professor Snuggly Pants
  • member icon

Reputation: 6824
  • View blog
  • Posts: 31,471
  • Joined: 10-May 07

Re: Using ** in Bash compound condition testing

Posted 18 July 2011 - 10:17 PM

You use the letters for digits (lt / less than gt / greater than) & use the double quotes for string comparisons.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1