LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   [: too many arguments (https://www.linuxquestions.org/questions/programming-9/%5B-too-many-arguments-882882/)

hd_pulse 05-26-2011 12:56 PM

[: too many arguments
 
Hey!

I am trying to find the output of the piece of code below:
Quote:


x=10 y=15
if [ $x % 2 -eq $y % 3 ]
then
echo "\n Barnie "

fi

But every time I run, it generates an error:

line 4: [: too many arguments

I don't understand the error.

When I modified it a little :

Quote:

x=10 y=15
if [ ( $x % 2 ) -eq ( $y % 3) ]
then
echo "\n Barnie "

fi

ie I covered the expression inside if with () brackets
then also an error is shown
line 5: syntax error near unexpected token `$x'
line 5: `if [ ( $x % 2 ) -eq ( $y % 3 ) ]'


Is there a limitation to the arguments inside test ([) command ??

Please help!

crts 05-26-2011 01:26 PM

Try it this way:
Code:

if [ $(( x % 2 )) -eq $(( y % 3 )) ];then
 echo "barnie"
fi


hd_pulse 05-26-2011 01:35 PM

Thanks Man!!

It worked.


All times are GMT -5. The time now is 05:47 PM.