Bash For Loop 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 the company Business Learn more about
Syntax Error Unexpected End Of File Bash Script
hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges syntax error unexpected end of file php Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.
Syntax Error Unexpected End Of File Wordpress
Join them; it only takes a minute: Sign up Bash: for loop in Makefile: unexpected end of file up vote 2 down vote favorite 1 I am writing a Makefile, which will list all headers included by a.cpp, b.cpp syntax error unexpected end of file shell script and c.h files. However, I got the error of unexpected EOF. Similar questions are always caused by the line terminator, like they used CRLF instead of LF for an EOL. However, my Text editor was set to using LF and I recheck this by delete all EOL and re-added. Unfortunately, the error still remains. Here are the codes: #!/bin/bash list-header: for file in a.cpp b.cpp b.h do echo "$file includes headers: " grep -E '^#include' $file | cut syntax error unexpected end of file python -f2 done I got this error message: for file in "Bigram.cpp client.cpp Bigram.h" /bin/sh: -c: line 1: syntax error: unexpected end of file" Thanks in advance for any help. bash makefile share|improve this question asked May 23 '15 at 12:50 Baozi CAI 94 An example where the "unexpected end of file" is caused by the different EOL formats. [link]stackoverflow.com/questions/6366530/… –Baozi CAI May 23 '15 at 12:53 A Makefile is not a bash script. –chepner May 23 '15 at 13:42 add a comment| 1 Answer 1 active oldest votes up vote 4 down vote accepted First note you have to escape $ that you want the shell to see, otherwise make will expand them before calling the shell. However, your main problem is that every logical line in a make recipe is a separate shell command. So, this rule: list-header: for file in a.cpp b.cpp b.h do echo "$file includes headers: " grep -E '^#include' $file | cut -f2 done will cause make to invoke the shell commands: /bin/sh -c 'for file in a.cpp b.cpp b.h' /bin/sh -c 'do' /bin/sh -c 'echo "ile includes headers: "' /bin/sh -c 'grep -E '^#include' ile | cut -f2' /bin/sh -c 'done' You need to use backslashes to "continue" a logical line across newlines if you want them all sent to the same shell, and you have to add semicolons to make t
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
Syntax Error Unexpected End Of File Unix
Business Learn more about hiring developers or posting ads with us Stack Overflow Questions syntax error unexpected end of file laravel Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers,
Syntax Error Unexpected End Of File Expecting Function (t_function)
just like you, helping each other. Join them; it only takes a minute: Sign up Bash syntax error: unexpected end of file with for loop up vote 1 down vote favorite #!/bin/bash cp ./Source/* ./Working/ 2> http://stackoverflow.com/questions/30412874/bash-for-loop-in-makefile-unexpected-end-of-file /dev/null echo "Done" for filename in *.zip;do unzip “$filename”; done In the above script, I am trying to copy all the files from source to working and unzip the files in working folder but I am geting igetting an error unexpected end of file shell share|improve this question edited May 20 '13 at 16:55 Quentin 487k56634805 asked May 20 '13 at 16:49 Aparna 23114 It’s probably unzip that reports this error. –Gumbo http://stackoverflow.com/questions/16654303/bash-syntax-error-unexpected-end-of-file-with-for-loop May 20 '13 at 16:57 As an aside, you can use -v with copy to output more results while copying. rsync is also another command with nice output. –cogsmos May 20 '13 at 17:09 add a comment| 2 Answers 2 active oldest votes up vote 3 down vote accepted It looks like you have different kinds of double quotes in "$filename", make sure both are ASCII double quotes (decimal 34, hex 22). Try analyzing your script with od -c scriptname share|improve this answer answered May 20 '13 at 16:58 Jens 36.2k863104 add a comment| up vote 0 down vote You have up to two problems here. First you quotes are not standard. You probably copy pasted from MS Word or something that automatically converts quotes. The second problem you may have is that your filenames may have spaces in it. This can cause all sorts of problems in scripts if you do not expect it. There are a few workarounds but the easiest is probably to change the IFS: OLDIFS=$IFS IFS="$(echo -e '\t\n')" # get rid of the space character in the IFS ... do stuff ... IFS=$OLDIFS share|improve this answer answered May 20 '13 at 17:01 cogsmos 448210 3 No need for messing with IFS if "$filename" is doublequoted. –Jens May 20 '13 at 17:02
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta http://unix.stackexchange.com/questions/193165/syntax-error-unexpected-end-of-file-bash-script Discuss the workings and policies of this site About Us Learn more http://linuxcommand.org/wss0100.php 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 syntax error 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 Syntax Error: unexpected end of file — Bash script [closed] up vote 0 down vote favorite 1 I am trying to create an spritz app. Everything syntax error unexpected 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 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 specifi
Out Of Trouble by William Shotts, Jr. Now that our scripts are getting a little more complicated, I want to point out some common mistakes that you might run into. To do this, create the following script called trouble.bash. 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 run this script, it should output the line "Number equals 1" because, well, number equals 1. If you don't get the expected output, check your typing; you made a mistake. Empty variables Edit the script to change line 3 from: number=1 to: number= and run the script again. This time you should get the following: [me@linuxbox me]$ ./trouble.bash /trouble.bash: [: =: unary operator expected. Number does not equal 1 As you can see, bash displayed an error message when we ran the script. You probably think that by removing the "1" on line 3 it created a syntax error on line 3, but it didn't. Let's look at the error message again: ./trouble.bash: [: =: unary operator expected We can see that ./trouble.bash is reporting the error and the error has to do with "[". Remember that "[" is an abbreviation for the test shell builtin. From this we can determine that the error is occurring on line 5 not line 3. First, let me say there is nothing wrong with line 3. number= is perfectly good syntax. You will sometimes want to set a variable's value to nothing. You can confirm the validity of this by trying it on the command line: [me@linuxbox me]$ number= [me@linuxbox me]$ See, no error message. So what's wrong with line 5? It worked before. To understand this error, we have to see what the shell sees. Remember that the shell spends a lot of its life substituting text. In line 5, the shell substitutes the value of number where it sees $number. In our first try (when number=1), the shell substituted 1 for $number like so: if [ 1 = "1" ]; then However, when we set number to nothing (number=), the shell saw this after the substitution: if [ = "1" ]; then which is an error. It also explains the rest of the error message we received. The "=" is a binary operator; that is, it expects two items to operate upon - one on each side. What the shell w