Cygwin Shell Script Syntax Error Unexpected End Of File
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 bash script syntax error unexpected end of file the company Business Learn more about hiring developers or posting ads with us Stack Overflow linux syntax error unexpected end of file Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of
Syntax Error: Unexpected End Of File Bash
4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Cygwin error when doing if…then…fi - Bash script up vote 4 down vote favorite I just started bash
Install Dos2unix In Cygwin
shell programming. I have installed Cygwin on my Windows 7 computer. I started writing a script using this tutorial. My script requires an argument to be passed to it, if it doesn't it should display an error message. This is the code directly from the tutorial and the same one in my code: [ $# -eq 0 ] && { echo "usage: someArgument"; exit 1; } When I do the following: sh ./myscript.sh syntax error near unexpected token `fi' it gives me this error: -bash: /home/Me/myscript.sh: line 5: syntax error: unexpected end of file "Unexpected end of file" means I have missed a fi or done, etc. somewhere. I double-checked my code, but found nothing. Plus, when I comment out the line the script works perfectly fine. I tried using a if...then...fi: if [ $# -eq 0 ] then echo "usage: someArgument" exit 1; fi but to no avail! Please help, it's been stumping me. linux bash shell if-statement cygwin share|improve this question asked Jul 15 '12 at 6:38 Arka Majumdar 1,4981336 2 Consider providing an exact script reproducing your problem. It is not clear where your line "5" is. –user405725 Jul 15 '12 at 6:41 @torrentialcoding I am using Notepad++. I just noticed in the bottom right corner the words change from Dos/Windows to UNIX when I run dos2unix on the script (see my answer). –Arka Majumdar Jul 15 '12 at 8:33 @Java I believe Notepad++ allows you to save a file in Unix mode. This will save you an extra step of having to run the dos2unix tool to make your scripts usable. –torrential coding Jul 15 '12 at 8:51 @torrentialcoding Yeah it does. You can go to Edit>EOL Conversion>UNIX Format, or set as defaul
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
Unexpected Eof While Looking For Matching `"'
About Us Learn more about Stack Overflow the company Business Learn more about dos2unix windows hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join bash if else the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up syntax error: unexpected end of http://stackoverflow.com/questions/11489982/cygwin-error-when-doing-if-then-fi-bash-script file trying to run a simple bash script up vote 1 down vote favorite I really can't see what the issue is with my script is. I've considered missing quotations or other syntax errors. There's got to be something I'm missing. It's a very simple while loop script... #!/bin/bash c=1 while [ $c -le 5 ] do echo "Welcone $c times" c=$(( c++ )) done http://stackoverflow.com/questions/31216532/syntax-error-unexpected-end-of-file-trying-to-run-a-simple-bash-script I should mention that I'm running bash in cygwin on windows 7. thanks for the help bash cygwin eof share|improve this question asked Jul 4 '15 at 3:14 user3671613 1315 Could it be a strange Windows whitespace character? I tried running it in Linux and got the following output. –Huey Jul 4 '15 at 3:18 Did you use a windows editor (like Notepad) to create this file? If so, you've probably got end-of-line problems. Try using dos2unix to convert it (and read the man page, it overwrites its input). –bishop Jul 4 '15 at 3:24 probably is. I guess I just wont think about it too much and I'll try running it in linux when I can. (I can't install dos2unix in windows with sudo apt-get apparently... if you have a workaround I'd appreciate it ^ ^) –user3671613 Jul 4 '15 at 3:29 Use Notepad++ on windows. It has a setting for line endings (and syntax highlighting, etc). –ooga Jul 4 '15 at 3:31 tr -d '\r' < your-script.sh > temp.sh; mv temp.sh your-script.sh –anishsane Jul 4 '15 at 3:52 | show 1 more comm
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 http://www.unix.com/shell-programming-and-scripting/193609-cygwin-syntax-error-unexpected-end-file.html operating commands and unix operating commands cygwin syntax error: unexpected end of file Shell Programming and http://unix.stackexchange.com/questions/114138/shell-unexpected-end-of-file-error Scripting Thread Tools Search this Thread Display Modes #1 07-14-2012 ranjancom2000 Registered User Join Date: Apr 2011 Last Activity: 9 February 2016, 9:01 AM EST Posts: 65 Thanks: 0 Thanked 0 Times in 0 Posts cygwin syntax error: unexpected end of file Hi, I am getting error while running the script. "syntax error: syntax error unexpected end of file" if i do cat i cant see the content of the script also it is showing as HTML Code: cat test.sh doner /home/master/* /home/Priya/$i| while read i j The original script is Code: paste /home/names.txt /home/ip.txt | while read i j do mkdir $i cp -r /home/master/* /home/test/$i done Remove advertisements Sponsored Links ranjancom2000 View Public Profile Find all posts by ranjancom2000 #2 07-14-2012 alister Registered User Join Date: Dec unexpected end of 2009 Last Activity: 11 June 2014, 8:40 PM EDT Posts: 3,231 Thanks: 179 Thanked 976 Times in 790 Posts Looks like your script's "lines" are terminated by carriage returns instead of line feeds. Regards, Alister Remove advertisements Sponsored Links alister View Public Profile Find all posts by alister #3 07-14-2012 ranjancom2000 Registered User Join Date: Apr 2011 Last Activity: 9 February 2016, 9:01 AM EST Posts: 65 Thanks: 0 Thanked 0 Times in 0 Posts How i can remove the "carriage returns" ranjancom2000 View Public Profile Find all posts by ranjancom2000 #4 07-14-2012 Tribe Registered User Join Date: Jul 2012 Last Activity: 1 October 2016, 7:52 AM EDT Posts: 52 Thanks: 44 Thanked 4 Times in 4 Posts Could you try converting from windows format to unix format? Code: tr -d '\15\32' < winfile.sh > unixfile.sh More info on kb.iu.edu/data/acux.html Last edited by Tribe; 07-14-2012 at 05:00 AM.. Remove advertisements Sponsored Links Tribe View Public Profile Find all posts by Tribe #5 07-14-2012 alister Registered User Join Date: Dec 2009 Last Activity: 11 June 2014, 8:40 PM EDT Posts: 3,231 Thanks: 179 Thanked 976 Times in 790 Posts Quote: Originally Posted by Tribe Could you try converting from windows format to unix format? Code: tr -d '\15\32' < winfile.sh > unixfile.sh More info on kb.iu.edu/data/acux.html From the original post's output, it doesn't appear that the
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 ads with us Unix & Linux Questions Tags Users Badges Unanswered Ask Question _ Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. 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 top shell unexpected end of file error up vote 0 down vote favorite I had the below script working in a linux machine. page="$(curl http://www.google.com/| grep "title")" if [ -z "$page" ]; then echo "Empty page" else echo "Valid page" fi When am running in another machine, I am getting the error syntax error: unexpected end of file. Why am getting this error? shell shell-script share|improve this question asked Feb 8 '14 at 2:31 Ramesh 15.9k1674124 1 What are the machines? You have to watch for differences in the various shells. –slm♦ Feb 8 '14 at 3:48 add a comment| 1 Answer 1 active oldest votes up vote 2 down vote accepted You probably have invisible CR characters at the end of your lines (like when the file is in Microsoft format where the lines are terminated by the CRLF sequence of characters instead of just LF). Then, the shell complains that it reaches the end of the script file without finding a then following the if (there's just a then