Solved

Test brackets... too many arguments.. need help simplifying - Bourne Shell

Posted on 2011-02-17
3
678 Views
Last Modified: 2013-12-26
is there anyway I can simplify this?  ahh only have a like 20 minutes before this is due.. maybe my mind is cluttered but I can't find a way to simplify this statement without bourne shell giving me the argument

line 15: [: too many arguments

line 15 is specifically

if [ $1 % $num = 0 -a $2 % $num = 0 ]
#!/bin/sh
if [ $1 -gt $2 ]
then
num=$1
big=$1
small=$2
else
num=$2
big=$2
small=$1
fi

while [ $num -gt 0 ]
do
if [ $1 % $num = 0 -a $2 % $num = 0 ]
then
echo "GCD is $num"
num=0
else
num=`expr $num - 1`
fi
done

Open in new window

0
Comment
Question by:nocturn4l
  • 2
3 Comments
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 500 total points
ID: 34917615
if [ $(($1 % $num)) = 0 -a $(($2 % $num)) = 0 ]

0
 

Author Comment

by:nocturn4l
ID: 34917667
oh wow......thanks gonna check it out right now, i'll be back
0
 

Author Comment

by:nocturn4l
ID: 34917683
it worked!!!  thanks!!
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Background Still having to process all these year-end "csv" files received from all these sources (including Government entities), sometimes we have the need to examine the contents due to data error, etc... As a "Unix" shop, our only readily …
Utilizing an array to gracefully append to a list of EmailAddresses
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now