Bash For Loop Syntax Error Near Unexpected Token
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 bash syntax error near unexpected token done' or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x
Bash Syntax Error Near Unexpected Token Echo'
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 bash syntax error near unexpected token (' ubuntu takes a minute: Sign up Confusing syntax error near unexpected token 'done' up vote 4 down vote favorite I am trying to learn shell scripting, so I created a simple script with a loop that does nothing: #!/bin/bash names=(test test2 bash syntax error near unexpected token else' test3 test4) for name in ${names[@]} do #do something done however, when I run this script I get the following errors: ./test.sh: line 6: syntax error near unexpected token done' ./test.sh: line 6: done' What have I missed here? are shell scripts 'tab sensitive'? bash shell syntax for-loop syntax-error share|improve this question asked May 10 '12 at 12:38 fenerlitk 71651633 add a comment| 5 Answers 5 active oldest votes up vote 3 down vote accepted No, shell scripts are not
Bash Syntax Error Near Unexpected Token Fi'
tab sensitive (unless you do something really crazy, which you are not doing in this example). You can't have an empty while do done block, (comments don't count) Try substituting echo $name instead #!/bin/bash names=(test test2 test3 test4) for name in ${names[@]} do printf "%s " $name done printf "\n" output test test2 test3 test4 share|improve this answer edited May 10 '12 at 13:25 answered May 10 '12 at 12:51 shellter 22.4k53962 thanks that works =), is there a way I can get all output in one line? –fenerlitk May 10 '12 at 13:03 1 I'm glad that helped. See my edit. Good luck. –shellter May 10 '12 at 13:04 1 note that echo is very handy to print line-by-line data as the original example showed. Learn about printf (search here on S.O. for examples) as it really powerful and flexible aid in formatting the printing of your data. Good luck. –shellter May 10 '12 at 13:14 5 A valid "no-op" command is : –glenn jackman May 10 '12 at 13:37 1 @glennjackman : yes, good point. As fenerlitk said 'I am trying to learn shell scripting', I figured it made sense that s/he would want to see the loop in action. Fenerlitk , note that the ':' no-op command could have been put in your loop, preceding you comment, i.e. : # do something, and that loop would have finished, but you w
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 bash syntax error near unexpected token then' Learn more about hiring developers or posting ads with us Unix & Linux Questions Tags Users bash syntax error near unexpected token do' Badges Unanswered Ask Question _ Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other
Bash Syntax Error Near Unexpected Token Newline'
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 'while read line do' http://stackoverflow.com/questions/10534186/confusing-syntax-error-near-unexpected-token-done cause: “syntax error near unexpected token `done'” in Linux bash script up vote 1 down vote favorite I have a shell script which is running fine on Solaris platform but not working on Linux platform. The Failing code snippet is as following: [...] while read line do insert_into_table="insert into isam_subrack_tbl (select neId, friendlyName, eqptHolderActualType from $line)" $MYSQL_HOME/bin/mysql --socket=/tmp/mysql.sock -u$MYSQL_USER -p$MYSQL_PWD --host $MYSQL_HOST -Demlplatform -e "$insert_into_table" done < isam_subrack2.txt 2> /dev/null [...] When I run the script in http://unix.stackexchange.com/questions/225055/while-read-line-do-cause-syntax-error-near-unexpected-token-done-in-linux debug mode: bash-4.1$ sh -vvx test.sh [...] while read line do insert_into_table="insert into isam_subrack_tbl (select neId, friendlyName, eqptHolderActualType from $line)" $MYSQL_HOME/bin/mysql --socket=/tmp/mysql.sock -u$MYSQL_USER -p$MYSQL_PWD --host $MYSQL_HOST -Demlplatform -e "$insert_into_table" done < isam_subrack2.txt 2> /dev/null test.sh: line 98: syntax error near unexpected token `done' 'est.sh: line 98: `done < isam_subrack2.txt 2> /dev/null I tried dos2unix command but it did not help. Do you have any idea about why I am getting this error in this while loop? bash shell-script newlines share|improve this question edited Aug 24 '15 at 23:00 Gilles 369k666681119 asked Aug 24 '15 at 6:58 Murat 7818 1 Chances are the problem is in the [...] part. The Bourne and Korn shell found on Solaris allow unmatched quotes especially backticks for instance (while other shells are stricter on that). Try with only -x to see where it first stops to make sense. Above we don't see the PS4 (xtrace) output. –Stéphane Chazelas Aug 24 '15 at 7:06 2 What does file test.sh say? It looks like evn after dos2unix you have CR line endings. –muru Aug 24 '15 at 7:22 1 @Murat, just like Stephane mentioned, the problem seems to be in the [...]. Hope the file for example with vim and enable the syntax check. You should be able to see if something is not terminated. I have my share of cases where the script comp
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the http://unix.stackexchange.com/questions/239139/syntax-error-near-unexpected-token-done-when-looping-a-multi-statement-line 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 http://www.linuxquestions.org/questions/programming-9/bash-script-problem-syntax-error-near-unexpected-token-%60do-897377/ 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; syntax error 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 near unexpected token done when looping a multi-statement line up vote 0 down vote favorite I have the following code as part of a larger file (assume ${tools_urls}, ${tempFolder} syntax error near are global variables) download_tools() { for i in ${tools_urls}; do wget --no-check-certificate --directory-prefix=${tempFolder} ${i} || { echo "download failed" ; exit 3} done } When I run the script, I get the following error: syntax error near unexpected token 'done' However, if I remove the || { echo "download failed" ; exit 3} part of the loop, it works. Why is this the case? I can't see anything wrong with my code, and I can't find similar examples that involve multiple statements in one line bash shell-script scripting share|improve this question edited Oct 28 '15 at 6:56 chaos 27.4k65095 asked Oct 28 '15 at 6:51 9a3eedi 1134 add a comment| 1 Answer 1 active oldest votes up vote 3 down vote accepted A compound command with curly braces must have semicolons after each command in it: { cmd1; cmd2; cmd3; } So change it to: ... || { echo "download failed" ; exit 3; } Notice that the space after the last command is needed: The braces are reserved words, so they must be separated from the list (the commands)
Search HCL Search Reviews Search ISOs Go to Page... LinuxQuestions.org > Forums > Non-*NIX Forums > Programming Bash script problem: syntax error near unexpected token `do User Name Remember Me? Password Programming This forum is for all programming questions. The question does not have to be directly related to Linux and any language is fair game. Notices Welcome to LinuxQuestions.org, a friendly and active Linux Community. You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today! Note that registered members see fewer ads, and ContentLink is completely disabled once you log in. Are you new to LinuxQuestions.org? Visit the following links: Site Howto | Site FAQ | Sitemap | Register Now If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here. Having a problem logging in? Please visit this page to clear all LQ-related cookies. Introduction to Linux - A Hands on Guide This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter. For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own. Click Here to receive this Complete Guide absolutely free. Search this Thread 08-15-2011, 05:52 AM #1 rmaier9 LQ Newbie Registered: Aug 2011 Posts: 2 Rep: Bash script problem: syntax error near unexpected token `do Hello, I am having a problem running a bash script, and I get the following problem: Code: : command not found 'eatFlux: line 4: syntax error near unexpected token `do 'eatFlux: line 4: