Note that registered members see fewer ads, and ContentLink is completely disabled once you log in. If you'd like to contribute content, let us know. The [ command exits with 0 if its arguments -- which it interprets as a logical expression according to certain syntax rules -- evaluate to true. To fix this problem, change line 5 to read: if [ "$number" = "1" ]; then Now when the shell performs the substitution it will see: if [ "" = "1" http://gatoisland.com/syntax-error/bash-for-syntax-error.php
What is the sh -c command? I can only recreate the error you're citing by removing the space between the if and the [ character. UNIX is a registered trademark of The Open Group. It's a reserved word.
Browse other questions tagged bash shell if-statement or ask your own question. For example, when we were looking for our missing quotation we could have done this: #!/bin/bash number=1 if [ $number = "1" ]; then echo "Number equals 1 #else # echo Is the empty set homeomorphic to itself? More info here Also there's no need to use \n in every echo, because echo places newlines by default.
fi When writing #bash if [[ "$ORACLE_SID" != "Test" ]]; then ..... You probably think that by removing the "1" on line 3 it created a syntax error on line 3, but it didn't. It is common and well known since the beginning of Oracle database. –user75ponic Aug 23 '13 at 6:36 @Polppan : oh, thanks for that info ^^ –Olivier Dulac Aug Syntax Error Near Unexpected Token Fi' Cygwin This time you should get the following: [[email protected] me]$ ./trouble.bash /trouble.bash: [: =: unary operator expected.
UNIX is a registered trademark of The Open Group. Bash If Statement Command The parser for bash is complaining about a missing ';' after the (), but that's only part of the problem. The problem in the last examples is that you forgot a space between if and [ and between elif and [. grail View Public Profile View LQ Blog View Review Entries View HCL Entries Find More Posts by grail 05-10-2010, 09:03 PM #10 lucmove Member Registered: Aug 2005 Location: Brazil
My girlfriend has mentioned disowning her 14 y/o transgender daughter Is there a good way to get from Levoča to Lviv? Syntax Error Near Unexpected Token Fi Mac no need for [ [ ... ] ] "$answer" -eq "nano" && "vi" && "vim" && "emacs" will not test answer againt those four words. Least Common Multiple How to increase the population growth of the human race Modern soldiers carry axes instead of combat knives. In this case.
Please use the new version at LinuxCommand.org LinuxCommand Learningtheshell Writingshellscripts Script library SuperMan pages Who, What, Where, Why Tips, News And Rants Previous | Contents | Next Stay Out Of Trouble Use http://mywiki.wooledge.org/BashGuide instead. 1 members found this post helpful. Bash Script Syntax Error A name for a well-informed person who is not believed? Syntax Error Near Unexpected Token Fi' Shell Script asked 1 year ago viewed 553 times active 1 year ago Related 31Shell script fails: Syntax error: “(” unexpected1Bash completion throwing syntax error0Got “syntax error near unexpected end of file” in
Both if and then are keywords. http://gatoisland.com/syntax-error/bash-for-loop-syntax-error.php Is 8:00 AM an unreasonable time to meet with my graduate students and post-doc? grail View Public Profile View LQ Blog View Review Entries View HCL Entries Find More Posts by grail 05-10-2010, 10:15 AM #4 tuxdev Senior Member Registered: Jul 2005 Distribution: Not the answer you're looking for? Syntax Error Near Unexpected Token Fi' In Unix
The "=" is a binary operator; that is, it expects two items to operate upon - one on each side. Syntax Error Near Unexpected Token For Unexpected parent process id in output How would family relationships change if legal system uses collective punishment? I accepted a counter offer and regret it: can I go back and contact the previous company?
This is explained here You can use arithmetic expressions in if, so you don't have to use [ ] or [[ ]] at all in some cases. How to book a flight if my passport doesn't state my gender? Please visit this page to clear all LQ-related cookies. Syntax Error Fi Unexpected (expecting Then ) I actually don't know what it's looking for, but apparently the [ character is specially treated by the shell.
Another problem is that you didn't quote "$f" which might become a problem later. In fact, it was "spot on". You should get this: [[email protected] me]$ ./trouble.bash ./trouble.bash: line 8: unexpected EOF while looking for matching " ./trouble.bash: line 10 systax error: unexpected end of file Here we have another case his comment is here To critique or request clarification from an author, leave a comment below their post - you can always comment on your own posts, and once you have sufficient reputation you will
Password Protected Wifi, page without HTTPS - why the data is send in clear text? Yes, I googled. Join them; it only takes a minute: Sign up Here's how it works: Anybody can ask a question Anybody can answer The best answers are voted up and rise to the Type type [ to see what is really happening.
If you do not put a space after [ the shell will try to execute [whatever as command and fail. This site is not affiliated with Linus Torvalds or The Open Group in any way. Hot Network Questions Does mean=mode imply a symmetric distribution? Why can a Gnome grapple a Goliath?
UNIX is a registered trademark of The Open Group. Be sure to enter it exactly as written. #!/bin/bash number=1 if [ $number = "1" ]; then echo "Number equals 1" else echo "Number does not equal 1" fi When you Does mean=mode imply a symmetric distribution? The reason for the spaces after [ is because [ is also not syntax.