Contents
Is there a syntax error near the unexpected token Fi?
The shell keeps looking for the then, and finds a fi in command position. Since there’s an if that’s still looking for its then, the fi is unexpected, there’s a syntax error. You need to put a command terminator before then so that it’s recognized as a keyword.
When to assume true in the if FI statement?
It is recommended to be careful with the spaces between braces and expression. No space produces a syntax error. If expression is a shell command, then it will be assumed true if it returns 0 after execution. If it is a Boolean expression, then it would be true if it returns true.
What does the if FI statement do in Linux?
Unix / Linux – What is Shell? The if…fi statement is the fundamental control statement that allows Shell to make decisions and execute statements conditionally. The Shell expression is evaluated in the above syntax. If the resulting value is true, given statement (s) are executed. If the expression is false then no statement would be executed.
When does no space produce a syntax error?
No space produces a syntax error. If expression is a shell command, then it will be assumed true if it returns 0 after execution. If it is a Boolean expression, then it would be true if it returns true. The above script will generate the following result −
Why do I get syntax error, Unexpected?
I have a feeling this may be a simple syntax error that I’m just not seeing, as I’ve had a poke around the code and cannot figure out why I’m getting the above error. The code I’m working on is a tutorial from a SAMS books, on building a calendar class.
How to fix syntax error in one command?
To fix the error in a single command it’s usually enough to add or remove some incorrect characters that cause the syntax error in the command. Knowing how to fix the error in a script can take a bit more time, and for that I will use the following 5-step process: Run the script that contains the syntax error.
Which is the correct order to close the while loop?
The done and fi statements are correctly used to close the while loop and the if conditional statement. But they are used in the wrong order! The if statement is nested into the while loop so we should be closing the if statement first, using fi. And after that we can close the while loop using done.