Bash 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 bash if else site About Us Learn more about Stack Overflow the company Business Learn
Bash For Loop
more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question
1 Syntax Error End Of File Unexpected
x Dismiss Join 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 Bash
Syntax Error Unexpected End Of File In Shell Script
syntax error: unexpected end of file up vote 29 down vote favorite 14 Forgive me for this is a very simple script in Bash. Here's the code: #!/bin/bash # june 2011 if [ $# -lt 3 -o $# -gt 3 ]; then echo "Error... Usage: $0 host database username" exit 0 fi after running sh file.sh: syntax error: unexpected end of file bash syntax bash syntax error near unexpected token share|improve this question edited Jun 17 '13 at 10:26 fedorqui 108k30164211 asked Jun 16 '11 at 2:34 markcruz 174127 add a comment| 9 Answers 9 active oldest votes up vote 41 down vote accepted I think file.sh is with CRLF line terminators. run dos2unix file.sh then the problem will be fixed. You can install dos2unix in ubuntu with this: sudo apt-get install dos2unix share|improve this answer answered Jun 16 '11 at 2:50 clyfish 4,98311822 thanks guys! all of you are right. there's something non-unix character embedded on my code! thanks –markcruz Jun 16 '11 at 2:54 thanks! saved me a lot of time! surprised I need to google this many pages before running into this answer. –Derek Jul 3 '13 at 6:01 Whats the reason behind this problem? I usually work on Windows but need to transfer scripts to unix systems. –CMCDragonkai Nov 2 '13 at 16:06 3 Makes no change for me. Downvoting. Sorry. –Kees de Kooter Dec 5 '14 at 8:35 2 @KeesdeKooter I wouldn't say just because something didn't work for you that you should downvote it, cl
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 bash syntax error near unexpected token newline developers or posting ads with us Unix & Linux Questions Tags Users Badges Unanswered Ask Question syntax error unexpected end of file php _ Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; syntax error unexpected end of file wordpress 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 Syntax Error: unexpected end of file — Bash script [closed] up http://stackoverflow.com/questions/6366530/bash-syntax-error-unexpected-end-of-file vote 0 down vote favorite 1 I am trying to create an spritz app. Everything was working fine, but since yesterday I keep getting this error: ./spritz: line 176: syntax error: unexpected end of file I have checked the script file and everything seems perfect. I am confused, I have an if statement at last and it looks correct! Here is the last portion: #checks if speed is 150 157 if [[ $2 -eq 150 ]]; 158 then 159 starttime=$SECONDS 160 http://unix.stackexchange.com/questions/193165/syntax-error-unexpected-end-of-file-bash-script FS=$'\n' 161 for j in `grep --color=always -iP '\b[^aeiou\s]*[aeiou][^aeiou\s]*\K[aeiou]' $1`; 162 do 163 #Reads the text file in the centre of the screen 164 echo " ___________________" 165 echo " $j"; 166 echo " ___________________" 167 echo " Speed 150 wpm" 168 sleep 0.9; 169 clear; 170 done 171 endtime=$(($SECONDS - $starttime)) 172 echo "You read $words_read words in $endtime seconds!" 173 exit 8 174 fi bash shell-script share|improve this question edited Mar 29 '15 at 5:19 Anthon 47.4k1462125 asked Mar 29 '15 at 1:31 Scott Pearce 46117 closed as unclear what you're asking by mdpc, jasonwryan, Networker, Michael Homer, Archemar Mar 29 '15 at 8:23 Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question.If this question can be reworded to fit the rules in the help center, please edit the question. (0) It might have been more useful to show us a diff from the last version that worked. … … … … … … … … Some observations (that probably don’t relate to your current, specific problem): (1) I don’t know of any circumstance where you need an unescaped ; (semicolon) at the end of a line. You can delete the semicolons at the ends of lines 157, 161, 165, 168, and 169. (Or you can leave t
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 http://askubuntu.com/questions/340767/unexpected-eof-in-a-bash-script-why Discuss the workings and policies of this site About Us Learn more http://askubuntu.com/questions/145900/syntax-error-unexpected-end-of-file-simple-script about Stack Overflow the company Business Learn more about 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 syntax error 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 Unexpected EOF in a bash script, why? up vote 3 down vote favorite I can't normally run sh scripts. It's confusing. I set the permissions to 777 and +x so it should work with the 'sh' end of file 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 at 21:57 Braiam 38.8k1691153 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 S
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 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 it works: Anybody can ask a question Anybody can answer The best answers are voted up and rise to the top “syntax error: unexpected end of file” simple script up vote 1 down vote favorite i need some help for a very siple script, i don't get were the fault is. The script : #!/bin/bash declare -i s declare -i m declare -i h if [ "$3" < 50 ]; then s=$3+10 m=$2 h=$1 else if ["$2" < 50 ]; then s=$3-50 m=$2+1 h=$1 else s=$1-50 m=$2-50 h=$1+1 fi fi echo "$h:$m:$s" The script add 10sc to the time we've entered. I get this error message : "sub_change_dirrect: line 14: syntax error: unexpected end of file" bash scripts share|improve this question edited Jun 3 '12 at 12:54 adempewolff 5,60011943 asked Jun 3 '12 at 12:41 Sam 4444915 add a comment| 2 Answers 2 active oldest votes up vote 2 down vote accepted There are three obvious errors: On the line else s=$1-50 m=$2-50 h=$1+1 fi, the word fi is not treated as a keyword, because it is not the first word in the command. To the shell, this looks like three assignments that apply to the command fi. If you ever got to execute this line, you'd see an error bash: fi: command not found. Put fi on a line of its own (or put a ; before it). [ "$3" < 50 ] is the same as [ "$3" ] < 50 — it's the command [ … ] (which can also be written test) with the sole argument "$3", and with an input redirection from the file 50. Either use the numeric comparison operator -lt, or use an arithmetic instruction (( … )). The single bracket construct is an ordinary built-in command, so special characters such as < retain their normal meaning. The double parenthesis construct is special syntax, and you can use < as a numeric comparison operator inside. ["$2" < 50 ] is missing a space after the opening bracket. Also the usual convention in shell scripts is to put a newline after then and else. Furthermore, instead of an else block that consists entirely of an if statement, you should use elif. And please indent consistently. #!/bin/bash declare -i s declare -i m declare -i h if (( $3 < 50 )); then s=$3+