LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-26-2011, 12:56 PM   #1
hd_pulse
Member
 
Registered: Dec 2010
Posts: 35

Rep: Reputation: 0
[: 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!

Last edited by hd_pulse; 05-26-2011 at 01:01 PM.
 
Old 05-26-2011, 01:26 PM   #2
crts
Senior Member
 
Registered: Jan 2010
Posts: 2,020

Rep: Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757
Try it this way:
Code:
if [ $(( x % 2 )) -eq $(( y % 3 )) ];then
 echo "barnie"
fi
 
1 members found this post helpful.
Old 05-26-2011, 01:35 PM   #3
hd_pulse
Member
 
Registered: Dec 2010
Posts: 35

Original Poster
Rep: Reputation: 0
Thanks Man!!

It worked.
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] arguments if statement brownie_cookie Linux - Newbie 4 05-03-2011 04:59 AM
2.4 too few arguments Problem thomas55 Linux From Scratch 5 11-29-2005 12:00 PM
make arguments johnrage SUSE / openSUSE 2 11-29-2005 08:10 AM
C Function Arguments jpbarto Programming 6 04-23-2004 01:59 PM
More arguments in printf() AMMullan Programming 3 02-23-2004 02:29 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:18 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration