Eq binary operator expected
We can see that. Remember that " [ " is an abbreviation for the test shell builtin. From this we can determine that the error is occurring on line 5 not line 3. First, let me say there is nothing wrong with line 3. You will sometimes want to set a variable's value to nothing. You can confirm the validity of this by trying it on the command line:. To understand this error, we have to see what the shell sees. Remember that the shell spends a lot of its life expanding text.
It also explains the rest of the error message we received. What the shell is trying to tell us is that there is only one item and there should be a unary operator like "! This brings up an important thing to remember when you are writing your scripts. Consider what happens if a variable is set to equal nothing.
Here we have another case of a mistake in one line causing a problem later in the script. What happens is the shell keeps looking for the closing quotation mark to tell it where the end of the string is, but runs into the end of the file before it finds it. These errors can be a real pain to find in a long script. This is one reason you should test your scripts frequently when you are writing them so there is less new code to test. I also find that text editors with syntax highlighting make these kinds of bugs easier to find.
Finding bugs in your programs can sometimes be very difficult and frustrating. Here are a couple of techniques that you will find useful:. Isolate blocks of code by "commenting them out. Frequently, you will do this to a block of code to see if a particular problem goes away. By doing this, you can isolate which part of a program is causing or not causing a problem.
By commenting out the else clause and running the script, we could show that the problem was not in the else clause even though the error message suggested that it was. Use echo commands to verify your assumptions. As you gain experience tracking down bugs, you will discover that bugs are often not where you first expect to find them. A common problem will be that you will make a false assumption about the performance of your program.
You will see a problem develop at a certain point in your program and assume that the problem is there. This is often incorrect, as we have seen. To combat this, you should place echo commands in your code while you are debugging, to produce messages that confirm the program is doing what is expected. There are two kinds of messages that you should insert. The first type simply announces that you have reached a certain point in the program.
We saw this in our earlier discussion on stubbing. It is useful to know that program flow is happening the way we expect. The second type displays the value of a variable or variables used in a calculation or test. Hello, I'm kinda new to writing scripts. I have a script that has a list user names in a text file, and I'm trying to compare it to a user entered name.
Linux OS Dev Linux OS Dev 1. Thanks a lot guys. It was the ; causing the problems. Dunno why, cos I use it elsewhere sometimes without errors. Question has a verified solution. Sign up with Google. Sign up with LinkedIn. Sign up with Facebook. I would like to receive news, updates and offers from Experts Exchange.
A Simple Linux script to retrieve information from the web using xpath selection. Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…. The purpose of this article is to demonstrate how we can upgrade Python from version 2.
How to incorporate Contact Management into an Access database? Hi, this video explains a free download that you can incorporate into your Access databases, or use stand-alone for contact management.