Whats wrong with this If statement?

Hi
I am pretty new to bash scripting.I am trying to write the if statement in bash and it give me error. Can you please help me what I am doing wrong in If statement?

if [$DB_SIZE%$kk==0] && [$DB_SIZE/$kk<=$M] && [$DB_SIZE/$kk >= $divide]
then

			fector=$kk;
			divide=$DB_SIZE/$kk;
			echo "factor value:$fector"
			echo"divide value:$divide"
			

fi

line 1: [1024%2==0]: command not found

The [ and ] are actually command keywords like echo and ls . They have to have spaces around them so that bash can see they are "words".

Next - the && and || syntax is not recognized by [ but [[ does recognize it.

if  [[ [ $DB_SIZE % $kk==0 ] && [ $(( $DB_SIZE / $kk )) <= $M ] && [ $(($DB_SIZE / $kk )) >= $divide ]  ]]

Please note: I just lost my glasses so proof reading this is problematic - I may have a typo.

Hi Thanks for your reply with this I am getting this error

if  [[ [ ($DB_SIZE % $kk ) == 0 ] && [ ( $DB_SIZE / $kk ) <= $M ] && [ ($DB_SIZE / $kk ) >= $divide ]  ]];
then
.....

Error:  conditional binary operator expected



---------- Post updated at 08:01 AM ---------- Previous update was at 08:01 AM ----------

Hi Thanks for your reply with this I am getting this error


if  [[ [ ($DB_SIZE % $kk ) == 0 ] && [ ( $DB_SIZE / $kk ) <= $M ] && [ ($DB_SIZE / $kk ) >= $divide ]  ]];
then
.....

Error:  conditional binary operator expected



You removed all the syntax which lets it work to make it prettier. Try the code you were given.

The numeric operations like / work in $(( )) .
Within [ ] and [[ ]] you do numerical comparison with -eq (equivalent), -gt (greater than), -le (less|equal), etc.
Within $(( )) you do not need to $ -prefix referenced variables.

if [[ $(( DB_SIZE % kk )) -eq 0 && $(( DB_SIZE / kk )) -le $M && $(( DB_SIZE / kk )) -ge $divide ]]
then

Also the shell can handle && . Sometimes this is better readable

if [[ $(( DB_SIZE % kk )) -eq 0 ]] && [[ $(( DB_SIZE / kk )) -le $M ]] && [[ $(( DB_SIZE / kk )) -ge $divide ]]
then

---------- Post updated at 12:22 ---------- Previous update was at 12:08 ----------

The previous should work in all Posix-compliant shells.
The following works in bash (and ksh and zsh I think):

if (( DB_SIZE % kk == 0 && DB_SIZE / kk <= M && DB_SIZE / kk >= divide ))
then