While Loop Errors


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers While Loop Errors
# 1  
Old 05-07-2012
While Loop Errors

I have the following chunk of code...

Code:
while [ $answer != X || $answer != x ]

when I try to execute this script, it outputs an error "test: ] missing"

Is there a syntax error here?

Last edited by Scrutinizer; 05-07-2012 at 02:03 PM.. Reason: code tags
# 2  
Old 05-07-2012
Code:
while [ "$answer" != "x" ] || [ "$answer" != "X" ]

..except that this is a logic error and will loop forever. One or the other conditions will always evaluate to true and keep the loop going.

Try && instead of ||
# 3  
Old 05-07-2012
Even with substituting the || for &&, it gives me the same error message

test: ] missing
# 4  
Old 05-07-2012
Please post your entire script, then.
# 5  
Old 05-07-2012
Quote:
Originally Posted by itech4814
Even with substituting the || for &&, it gives me the same error message

test: ] missing
Did you also notice the double quotes and the extra square brackets that Corona688 introduced?
# 6  
Old 05-07-2012
Code:
answer=x
while [ $answer != X && $answer != x ]
do
echo "Phone Book"
echo "Phone Company"
echo "Company Number"
echo ""
echo ""
echo "A - Add a new line in the phone book"
echo "D - Delete a line from the phone book"
echo "M - Modify a line in the phone book"
echo "I - Inquire on a name in the phone book"
echo "X - Exit"
echo ""
echo ""
echo "What would you like to do? \c"
read answer
case $answer in



That's all i have so far...

Last edited by Corona688; 05-07-2012 at 02:01 PM..
# 7  
Old 05-07-2012
Try the answer I actually gave you.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk loop using array:wish to store array values from loop for use outside loop

Here's my code: awk -F '' 'NR==FNR { if (/time/ && $5>10) A=$2" "$3":"$4":"($5-01) else if (/time/ && $5<01) A=$2" "$3":"$4-01":"(59-$5) else if (/time/ && $5<=10) A=$2" "$3":"$4":0"($5-01) else if (/close/) { B=0 n1=n2; ... (2 Replies)
Discussion started by: klane
2 Replies

2. Shell Programming and Scripting

Reset while loop to loop same file multiple times

Hi, I want to read file multiple times. Right now i am using while loop but that is not working. ex. While read line do while read line2 do echo stmt1 #processing some data based on data., done < file2.txt done < file1.txt # This will have 10... (4 Replies)
Discussion started by: tmalik79
4 Replies

3. Shell Programming and Scripting

Array Variable being Assigned Values in Loop, But Gone when Loop Completes???

Hello All, Maybe I'm Missing something here but I have NOOO idea what the heck is going on with this....? I have a Variable that contains a PATTERN of what I'm considering "Illegal Characters". So what I'm doing is looping through a string containing some of these "Illegal Characters". Now... (5 Replies)
Discussion started by: mrm5102
5 Replies

4. Shell Programming and Scripting

BASH loop inside a loop question

Hi all Sorry for the basic question, but i am writing a shell script to get around a slightly flaky binary that ships with one of our servers. This particular utility randomly generates the correct information and could work first time or may work on the 12th or 100th attempt etc !.... (4 Replies)
Discussion started by: rethink
4 Replies

5. Shell Programming and Scripting

Null Handling in Until loop. . .loop won't stop

Hi Im running this script, which is supposed to find the max value build some tables and then stop running once all the tables are built. Thing is , it keeps assigning a null value to $h and then $g is null so it keep building tables i.e. testupdateNUL. How can I stop this? Here is what I have: ... (4 Replies)
Discussion started by: brandono66
4 Replies

6. Shell Programming and Scripting

Using variables created sequentially in a loop while still inside of the loop [bash]

I'm trying to understand if it's possible to create a set of variables that are numbered based on another variable (using eval) in a loop, and then call on it before the loop ends. As an example I've written a script called question (The fist command is to show what is the contents of the... (2 Replies)
Discussion started by: DeCoTwc
2 Replies

7. UNIX for Dummies Questions & Answers

Major OS errors/Bash errors help!!!!

Hi all, dummy here.... I have major errors on entering the shell. On login I get: -bash: dircolors: command not found -bash: tr: command not found -bash: fgrep: command not found -bash: grep: command not found -bash: grep: command not found -bash: id: command not found -bash: [: =: unary... (12 Replies)
Discussion started by: wcmmlynn
12 Replies

8. AIX

Adapter Errors and Link Errors

$ errpt | more IDENTIFIER TIMESTAMP T C RESOURCE_NAME DESCRIPTION 3074FEB7 0802050205 T H fscsi1 ADAPTER ERROR B8113DD1 0802050205 T H fcs1 LINK ERROR B8113DD1 0802050205 T H fcs1 LINK ERROR 3074FEB7 0802050205 T H fscsi0 ADAPTER ERROR B8113DD1 ... (2 Replies)
Discussion started by: mcastill66
2 Replies

9. UNIX for Advanced & Expert Users

Adapter Errors and Link Errors

$ errpt | more IDENTIFIER TIMESTAMP T C RESOURCE_NAME DESCRIPTION 3074FEB7 0802050205 T H fscsi1 ADAPTER ERROR B8113DD1 0802050205 T H fcs1 LINK ERROR B8113DD1 0802050205 T H fcs1 LINK ERROR 3074FEB7 0802050205 T H fscsi0 ADAPTER ERROR B8113DD1 ... (0 Replies)
Discussion started by: mcastill66
0 Replies

10. UNIX for Advanced & Expert Users

Boot loop errors caused by RC.CONF

Hello all! I am praying someone can help me. I have been trying to install dual nics on my FreeBSD box. In my attempts I edited my RC.CONF file. I must have editing something wrong, because during the boot sequence, my machine gets through bringing up most of the services then it stops and gets... (5 Replies)
Discussion started by: ezekiel61
5 Replies
Login or Register to Ask a Question