BASH If conditional always returns "True"

Jonathan Ambriz

The code I wrote to solve a challenge keeps giving me a response of "True" and I have no idea why. I've played with the syntax and keep getting "True", so there's probably something I'm not understanding about the way Bash works.

I apologize if this is too simple or if there are similar questions out there. I looked but don't know how to phrase the issue.

The test values input are n=3 x=3 y=4 (says true, should be false) and n=12 x=3 x=4 (does not reach this point of the test.

#!/bin/bash

read n
echo "n is " $n

read x
echo "x is " $x

read y
echo "y is " $y

if [[ ((n%x==0 && n%y==0)) ]]; then
    echo "true"
else
    echo "false"
fi
Aplet123

Get rid of the unnecessary [[]]. Your new if statement would look like if ((n%x==0 && n%y==0)).

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related