Sponsored Content
Full Discussion: Multiple while statements?
Top Forums Shell Programming and Scripting Multiple while statements? Post 302576145 by nickzourdos on Wednesday 23rd of November 2011 09:20:34 PM
Old 11-23-2011
Question Multiple while statements?

I'm working on a script for class as a final project. We have to ask for values (city, state, zip) five times, but the state can only be MI, IN, IL, or OH. I'm trying to do this with a while loop inside of a while loop, but I have no idea how to do it properly.

Here's what I have so far:

Code:
COUNT=0
while [ "$COUNT" -lt "5" ]; do
  clear
  echo "Enter City: "; read CITY
  echo "Enter State: "; read STATE
        while [[ "$STATE" != "MI" && "$STATE" != "IN" && "$STATE" != "IL" && "$STATE" != "OH" ]]; do
          echo "Sorry, that's not an accepted state."; read STATE
        done
  echo "Enter Zip: "; read ZIP
COUNT="$COUNT"+1
done
sleep 5

I have a feeling I'm way off... and I have no idea how to fix it.

Help is appreciated!

Last edited by nickzourdos; 11-23-2011 at 10:36 PM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

multiple conditions in if statements

Hi all, I'm confused about the proper syntax for multi-conditional if then statements. I'm trying to set limitations on info input on the command line.. i.e. if ] ;then $x=$vr1 else print "You have entered an invalid option." Can someone please clue me in on what is wrong with my syntax;... (3 Replies)
Discussion started by: tim mauger
3 Replies

2. Shell Programming and Scripting

multiple 'if' statements out of array

I want to do multiple comparisons on a series of numbers from an array: I send the numbers in file1 through want to print out some info from file2 based on some conditions. The syntax just isn't correct??? awk ' NR==FNR{ a=$0 next ... (2 Replies)
Discussion started by: dcfargo
2 Replies

3. Shell Programming and Scripting

How do I execute multiple statements within If then else

Please help me. I have been doing this for several hours. Here is the code if then echo a b c d >> file.txt echo 1111 >> file.txt fi The reason I want the two echo is because I want these statements printed on multiple lines. I keep getting error . First it tells me... (2 Replies)
Discussion started by: asemota
2 Replies

4. Shell Programming and Scripting

Running multiple if statements

Hi, Hav automated a process, and it is working fine. for first process alone status = ` ps -ef |grep a ` if then echo " Success" > temp/logfile else echo " Failure" > temp/logfile fi Now I hav to write script to automated some 2 process and then send mail using cron.. ... (5 Replies)
Discussion started by: NehaKrish
5 Replies

5. Shell Programming and Scripting

execute multiple statements in if-else

how can we execute multiple statements in else condition i have if then statement else statements fi in else condition i have multiple statements but it executing only one statement is there any way to execute multiple statements (4 Replies)
Discussion started by: nani1984
4 Replies

6. Shell Programming and Scripting

multiple echo statements in if condition

Hi , I have a peculiar problem. i have an if block like this if ; then echo " todays date is " ${date} >> log_file echo " file count is " $ count >> log_file mv filename1 filename 2 else echo "no files available ">> log_file fi the echo statement "no files available " is not... (2 Replies)
Discussion started by: wizardofoz
2 Replies

7. Shell Programming and Scripting

Multiple if Statements

Hi All, I need to check for 3 conditions and if all the 3 are not satified need to say that services are not running.... is the below code correct. #********** Check to see if Service 1 is still running************** if then echo "$datetimestamp: Service1 is not running" >>... (4 Replies)
Discussion started by: ch33ry
4 Replies

8. Shell Programming and Scripting

Multiple If statements in bash problem

Hi everyone, May you help me with the correct syntax of the follow bash statements please X=10 if ]; then echo "The value is between 1 and 5" for ((i=1;i<=${X})); do echo $i done else if ]; then echo "The value is between 6 and 10" for ((i=1;i<=${X})); do ... (5 Replies)
Discussion started by: Ophiuchus
5 Replies

9. UNIX for Dummies Questions & Answers

Multiple if statements

exmaple: file1 and file2 has 1 bit if then exit else send out email fi if then exit else send out email fi it exits the 1st if. did not continue with my 2nd if. thanks in advanced. Please use CODE tags are suggested on every page when you post an item in... (7 Replies)
Discussion started by: lawsongeek
7 Replies

10. Shell Programming and Scripting

Using multiple 'for' statements

Hello, I am new to scripting and I am trying to write a simple script that creates users and adds their passwords from two files; one a user list file and another a password list file. For example, I have two files already. $ cat file1 andy stephane aby paul $ cat file2 123 234... (4 Replies)
Discussion started by: FemoTheDon
4 Replies
MAXDB_FETCH_ARRAY(3)							 1						      MAXDB_FETCH_ARRAY(3)

maxdb_fetch_array - Fetch a result row as an associative, a numeric array, or both

       Procedural style

SYNOPSIS
mixed maxdb_fetch_array (resource $result, [int $resulttype]) DESCRIPTION
Object oriented style mixed maxdb_result::fetch_array ([int $resulttype]) Returns an array that corresponds to the fetched row or NULL if there are no more rows for the resultset represented by the $result param- eter. maxdb_fetch_array(3) is an extended version of the maxdb_fetch_row(3) function. In addition to storing the data in the numeric indices of the result array, the maxdb_fetch_array(3) function can also store the data in associative indices, using the field names of the result set as keys. Note Field names returned by this function are case-sensitive. Note This function sets NULL fields to the PHP NULL value. If two or more columns of the result have the same field names, the last column will take precedence and overwrite the earlier data. In order to access multiple columns with the same name, the numerically indexed version of the row must be used. The optional second argument $resulttype is a constant indicating what type of array should be produced from the current row data. The possible values for this parameter are the constants MAXDB_ASSOC, MAXDB_ASSOC_UPPER, MAXDB_ASSOC_LOWER, MAXDB_NUM, or MAXDB_BOTH. By default the maxdb_fetch_array(3) function will assume MAXDB_BOTH, which is a combination of MAXDB_NUM and MAXDB_ASSOC for this parameter. By using the MAXDB_ASSOC constant this function will behave identically to the maxdb_fetch_assoc(3), while MAXDB_NUM will behave identi- cally to the maxdb_fetch_row(3) function. The final option MAXDB_BOTH will create a single array with the attributes of both. By using the MAXDB_ASSOC_UPPER constant, the behaviour of this function is identical to the use of MAXDB_ASSOC except the array index of a column is the fieldname in upper case. By using the MAXDB_ASSOC_LOWER constant, the behaviour of this function is identical to the use of MAXDB_ASSOC except the array index of a column is the fieldname in lower case. RETURN VALUES
Returns an array that corresponds to the fetched row or NULL if there are no more rows in resultset. EXAMPLES
Example #1 Object oriented style <?php $maxdb = new maxdb("localhost", "MONA", "RED", "DEMODB"); /* check connection */ if (maxdb_connect_errno()) { printf("Connect failed: %s ", maxdb_connect_error()); exit(); } $query = "SELECT name, state FROM hotel.city ORDER by zip"; $result = $maxdb->query($query); /* numeric array */ $row = $result->fetch_array(MAXDB_NUM); printf ("%s (%s) ", $row[0], $row[1]); /* associative array */ $row = $result->fetch_array(MAXDB_ASSOC); printf ("%s (%s) ", $row["NAME"], $row["STATE"]); /* associative and numeric array */ $row = $result->fetch_array(MAXDB_BOTH); printf ("%s (%s) ", $row[0], $row["STATE"]); /* free result set */ $result->close(); /* close connection */ $maxdb->close(); ?> Example #2 Procedural style <?php $link = maxdb_connect("localhost", "MONA", "RED", "DEMODB"); /* check connection */ if (maxdb_connect_errno()) { printf("Connect failed: %s ", maxdb_connect_error()); exit(); } $query = "SELECT name, state FROM hotel.city ORDER by zip"; $result = maxdb_query($link, $query); /* numeric array */ $row = maxdb_fetch_array($result, MAXDB_NUM); printf ("%s (%s) ", $row[0], $row[1]); /* associative array */ $row = maxdb_fetch_array($result, MAXDB_ASSOC); printf ("%s (%s) ", $row["NAME"], $row["STATE"]); /* associative and numeric array */ $row = maxdb_fetch_array($result, MAXDB_BOTH); printf ("%s (%s) ", $row[0], $row["STATE"]); /* free result set */ maxdb_free_result($result); /* close connection */ maxdb_close($link); ?> The above example will output something similar to: New York (NY) New York (NY) Long Island (NY) SEE ALSO
maxdb_fetch_assoc(3), maxdb_fetch_row(3), maxdb_fetch_resource(3). PHP Documentation Group MAXDB_FETCH_ARRAY(3)
All times are GMT -4. The time now is 07:41 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy