Linux Syntax Error End Of File Unexpected Expecting Then
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting java syntax error: end of file unexpected (expecting ")") ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the
Syntax Error: "fi" Unexpected (expecting
Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a aapt: syntax error: end of file unexpected (expecting ")") minute: Sign up Syntax error: end of file unexpected (expecting “then”) up vote 1 down vote favorite 2 I am making this code for a minecraft server plugin updater I am a new shell scripter so I don't know alot... when
/bin/sh: 1: Syntax Error: End Of File Unexpected (expecting "then" )
I run this code I get a error: #!/bin/sh export PATH=$PATH:. #Options PLUGINDOWNLOADLINK=http://api.bukget.org/3/plugins/bukkit/$PLUGINNAME/latest/download # Plugin folder if [ -f $PWD\plugins ]; then PLUG=$PWD\plugins else PLUG=$PWD\plug-ins fi cd $PLUG if [ ! -f .\update ]; then mkdir update echo Making Directory "update".. fi # Plugins Found for i in $( ls ); do PLUGINNAME=$i done cd .\update wget $PLUGINDOWNLOADLINK # No Plugins Found if [ ! -f $PLUG ]; then echo echo echo No plugin found. echo echo echo echo Plugins can be downloaded syntax error unexpected here: echo http://dev.bukkit.org/bukkit-plugins fi # stop sleep 3s exit I get this error: Syntax error: end of file unexpected (expecting "then") so I put "then" in the place it wanted me to and ran it again: it gave me this error now: Syntax error: end of file unexpected I wrote it on windows 7 notepad++ how can I fix this? linux shell unix minecraft share|improve this question edited Aug 9 '13 at 21:43 asked Aug 9 '13 at 21:22 user2649805 13115 The code you posted does not cause the error. –choroba Aug 9 '13 at 21:26 then what does? –user2649805 Aug 9 '13 at 21:27 or have you composed this script in a Windows-based editor, and then copied it you your linux server without running dos2unix myPluginScript. ? Good luck. –shellter Aug 9 '13 at 21:34 ya exept it is a pi –user2649805 Aug 9 '13 at 21:35 dos2unix does not work –user2649805 Aug 9 '13 at 21:39 | show 1 more comment 2 Answers 2 active oldest votes up vote 3 down vote accepted I have met the same problem. And the problem is the format of the file is "dos", but in linux shell requires "unix", so I install the "dos2unix" $ sudo apt-get install dos2unix or if you use emacs, you can do this: C-x RET f unix Good luck :) share|improve this answer answered Sep 1 '13 at 1:23 Ni Xiaon
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more
Syntax Error: End Of File Unexpected (expecting "fi")
about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users
Syntax Error Near Unexpected Token Done
Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping syntax error near unexpected token fi each other. Join them; it only takes a minute: Sign up Syntax error: “fi” unexpected (expecting “then”) in bash script up vote 1 down vote favorite I try to do the script: #!/bin/bash IP='192.168.1.1' fping -c1 -t300 $IP http://stackoverflow.com/questions/18155852/syntax-error-end-of-file-unexpected-expecting-then 2>/dev/null 1>/dev/null if [ "$?" = 0 ] then echo "Host found" else echo "Host not found" fi and i turn it: pi@raspberrypi ~ $ sh /home/pi/sh/test.sh /home/pi/sh/test.sh: 9: /home/pi/sh/test.sh: Syntax error: "fi" unexpected (expecting "then") where is the problem? bash command-line scripting sh share|improve this question edited May 4 '15 at 21:15 Jahid 8,61742348 asked May 4 '15 at 18:44 Kwiatkowski 4217 1 Sorry, I can not reproduce this problem with sh, bash and dash. http://stackoverflow.com/questions/30037627/syntax-error-fi-unexpected-expecting-then-in-bash-script –Cyrus May 4 '15 at 18:51 1 As written that shell script is syntactically valid. Are you sure that's the exact script you tested with? Copy and paste from here into a new file and run that. Does it work? –Etan Reisner May 4 '15 at 18:52 1 Crossposting: askubuntu.com/questions/618260/script-sh-syntax-error –Cyrus May 4 '15 at 19:00 1 It's probable that your script has DOS line endings. Saving your script gives me a similar syntax error in dash (although it's an unexpected end-of-file rather than unexpected "fi"). You might have mixed line endings; see stackoverflow.com/q/3773649/1126841. –chepner May 4 '15 at 19:06 add a comment| 2 Answers 2 active oldest votes up vote 4 down vote accepted You can try $ dos2unix /home/pi/sh/test.sh and run it again. share|improve this answer answered May 4 '15 at 20:01 Diego Torres Milano 39.4k55988 add a comment| up vote 2 down vote Most probably this is because carriage-return \r in your script. Try run this command to clean-up your script. Just run once. Original file will be backed up. perl -pi.bak -e 's/\r$//' /home/pi/sh/test.sh share|improve this answer edited May 4 '15 at 19:16 answered May 4 '15 at 19:07 tivn 1,39739 add a comment| Your Answer draft saved draft discarded Sign up or log in Sign up using Google Sign up using Facebook Sign up using Email and Password Post
communities company blog Stack Exchange Inbox Reputation and Badges sign up log in tour help Tour Start here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about http://askubuntu.com/questions/340767/unexpected-eof-in-a-bash-script-why hiring developers or posting ads with us Ask Ubuntu Questions Tags Users Badges Unanswered Ask Question _ Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute: Sign up Here's how http://www.unix.com/shell-programming-and-scripting/194005-i-cant-get-what-im-doing-wrong.html it works: Anybody can ask a question Anybody can answer The best answers are voted up and rise to the top Unexpected EOF in a bash script, why? up vote 3 down vote favorite I can't normally run sh scripts. syntax error It's confusing. I set the permissions to 777 and +x so it should work with the 'sh' command, right... But it's working very strange. For example this scripts works ok: echo "hello" it prints "hello" with no errors. But this script: #!/bin/bash for i in `seq 1 5`; do echo $i done ...outputs this error: Syntax error: end of file unexpected (expecting "done") Is there something wrong with that loop? command-line bash scripts share|improve this question edited Sep 3 '13 end of file at 21:57 Braiam 39.1k1693154 asked Sep 3 '13 at 8:29 user568021 2952619 How do you run the above script? The loop it looks ok. –Radu Rădeanu Sep 3 '13 at 8:32 I run it with the sh command: sh script.sh –user568021 Sep 3 '13 at 8:36 You defined bash and not sh for your script, so run it with bash script.sh –Frantique Sep 3 '13 at 8:37 2 Are you sure that you have the last line (done) in your original script (script.sh)? –Radu Rădeanu Sep 3 '13 at 8:38 @Frantique This problem does nothing have to do with your observation. –Radu Rădeanu Sep 3 '13 at 8:41 | show 2 more comments 1 Answer 1 active oldest votes up vote 7 down vote accepted The problem it is, that you probably made a Ctrl+C Ctrl+V from a website, and the end-of-line char there was something strange, not printable character. (You can make it visible by dumping to hex the file.) Please open your file in an editor, and retype everything manually, or at least remove the last eol characters, save your work, and try again. share|improve this answer answered Sep 3 '13 at 8:42 Frantique 5,4561637 add a comment| Your Answer draft saved draft discarded Sign up or log in Sign up using Google Sign up using Facebook Sign up using Email and Password Post as a guest
Scripting Unix shell scripting - KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and shell scripts and shell scripting languages here. Search Forums Show Threads Show Posts Tag Search Advanced Search Unanswered Threads Find All Thanked Posts Go to Page... linux operating commands and unix operating commands I can't get what I'm doing wrong! Shell Programming and Scripting Tags help read variable Page 1 of 4 1 234 > Thread Tools Search this Thread Display Modes #1 07-17-2012 kitay Registered User Join Date: Jul 2012 Last Activity: 28 August 2012, 7:07 PM EDT Posts: 8 Thanks: 1 Thanked 0 Times in 0 Posts I can't get what I'm doing wrong! I am making a shell script that will have "shortcuts" to do different tasks and I can't get what I'm doing wrong (this is just a test script) Code: read cake if [ $cake == "1" ] then echo "1 it is" fi it outputs: Code: 1: : bad variable namecake test.sh: 27: test.sh: Syntax error: end of file unexpected (expecting "then") Last edited by methyl; 07-17-2012 at 07:20 PM.. Reason: please use code tags Remove advertisements Sponsored Links kitay View Public Profile Find all posts by kitay #2 07-17-2012 complex.invoke Registered User Join Date: Nov 2009 Last Activity: 30 December 2015, 11:56 PM EST Location: BeiJing China Posts: 236 Thanks: 6 Thanked 28 Times in 8 Posts Code: read cake [[ "${cake}" == "1" ]] && echo "1 it is" Remove advertisements Sponsored Links complex.invoke View Public Profile Find all posts by complex.invoke #3 07-17-2012 Scott Administrator Join Date: Jun 2009 Last Activity: 18 October 2016, 3:58 AM EDT Location: Zürich Posts: 8,595 Thanks: 342 Thanked 1,092 Times in 948 Posts Perhaps just missing a ; (semi-colon) after ]? Code: if [ ... ]; then edit: and as pointed out by huaihaizi3, you should add quotes around "$cake" Scott View Public Profile Find all posts by Scott #4 07-17-2012 methyl Advisor Join Date: Mar 2008 Last Activity: 8 June 2016, 9:58 PM EDT Posts: 6,402 Thanks: 288 Thanked 676 Times in 645 Posts First impression: Missing newline before "then", no quotes round "$cake". Code: read cake if [ "$cake" == "1" ] then echo "1 it is" fi Please post what Operating System you are running and what Shell you use. The syntax posted suggests that the Sh