1 Replies - 2062 Views - Last Post: 25 March 2011 - 12:34 PM Rate Topic: -----

#1 toyotaki  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 02-February 11

shell script: while loop / equal check statement

Posted 25 March 2011 - 10:28 AM

Hello,

I am having this code where it seems that there is a mistake at the while loop. Can someone help me find out what's going on?

accept=0
while [ $accept -eq 0 ]
do
        echo "Give a name:"
        read name
        accept=`java CheckName $name`
done


What I am trying to do is to have a variable "accept" which is initialized with the value 0 (number). While the value of accept is 0 I want to go into the loop and give the user the order "Give a name:" and let the user give a name. After reading the name I call a .java program that checks the name and prints on screen 0 or 1. I want this printed message to be stored in variable "accept". I want the while loop to me executed until the .java program returns 1 which means that the name is accepted.

The shell script seems to have a mistake on to line with the while check statement
while [ $accept -eq 0 ]

The mistake shown on screen is:" [: too many arguments"

Is This A Good Question/Topic? 0
  • +

Replies To: shell script: while loop / equal check statement

#2 brds  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 76
  • View blog
  • Posts: 515
  • Joined: 22-October 08

Re: shell script: while loop / equal check statement

Posted 25 March 2011 - 12:34 PM

If you checked the man page for your shell it would provide you with the correct syntax for while. It looks like your using sh/bash/ksh or some flavour thereof so Id have to say...

You are missing a ; on your while statement.
while [ $accept -eq 0 ];


Was This Post Helpful? 1
  • +
  • -

Page 1 of 1