Bash While Loop Syntax Error
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 While No Error
site About Us Learn more about Stack Overflow the company Business Learn more bash while 1 100 about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x android shell script syntax error do 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 while
Python While Loop Syntax Error
loop syntax error in do up vote 0 down vote favorite I´m trying do do a simple counter: max=100 count=1 while [[ $count -le $max]] do echo "$count" ((count++)) done This gives me a syntax error in conditional expression near do. What´s my issue? (probably something obvious) The idea is then to raise the max from 100 to 200 and so forth in a
Bash Syntax Error Near Unexpected Token Done'
superior loop so I will get a new file to manipulate with a python program 100 lines each time, but that´s irrelevant here. bash while-loop share|improve this question edited Jun 11 '14 at 17:04 Zefnus 3,26431942 asked Oct 11 '12 at 13:33 AWE 1,12371734 1 see my post, need an extra space –Gilles Quenot Oct 11 '12 at 13:42 add a comment| 2 Answers 2 active oldest votes up vote 2 down vote accepted Your mistake is that it need one more space in [[ $count -le 100]] max=100 count=1 while [[ $count -le $max ]] do echo "$count" ((count++)) done Another solution : while ((count < max+1)); do echo $((count++)); done or for ((i=count; i 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 bash syntax error near unexpected token else' Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is bash syntax error invalid arithmetic operator a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Bash error: syntax error near unexpected token `done' up vote 0 down vote favorite http://stackoverflow.com/questions/12840769/bash-while-loop-syntax-error-in-do I wrote a really simple file explorer using ls with a shell script. I used a while loop to make the script run forever (until Ctrl+C), but the while loop doesn't seem to work. I get this error ./fileexplorer: line 5: syntax error near unexpected token `done' ./fileexplorer: line 5: `done'` My code is this: #!/bin/bash ls -l $1 while : browse() done function browse() { read file; if [ http://stackoverflow.com/questions/31855596/bash-error-syntax-error-near-unexpected-token-done -f $file ] if test -e $file echo "Starting $file with nano." echo "Press a key to open the file." pause nano $file if test -d $file ls -l $file } bash while-loop share|improve this question asked Aug 6 '15 at 12:19 m654 1347 1 paste your code in shellcheck.net –Jahid Aug 6 '15 at 12:21 add a comment| 2 Answers 2 active oldest votes up vote 0 down vote accepted Below script should work .. #!/bin/bash function browse() { read file; if [ -f $file ] then if [ -e $file ] then echo "Starting $file with nano." echo "Press a key to open the file." sleep 2 nano $file fi fi if [ -d $file ] then ls -l $file fi } ls -l $1 while true;do browse done share|improve this answer answered Aug 14 '15 at 4:06 Raghav 16 add a comment| up vote 1 down vote That's not the correct syntax, you need something like: while CONDITION ; do ACTION done Without the do, the done is indeed unexpected. In addition, your if statements should be of the form: if CONDITION ; then ACTION fi The bash man page shows the correct forms in more detail: if list; then list; [ elif list; 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 http://unix.stackexchange.com/questions/225055/while-read-line-do-cause-syntax-error-near-unexpected-token-done-in-linux 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 https://www.digitalocean.com/community/questions/syntax-error-near-unexpected-token-done 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 syntax error The best answers are voted up and rise to the top 'while read line do' 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 bash syntax error $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 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, have one accepted answer. Are you sure you want to replace the current answer with this one? Yes, I'm sure. Changed your mind? You previously marked this answer as accepted. Are you sure you want to unaccept it? Yes, I'm sure. Sign Up Log In submit Tutorials Questions Projects Meetups Main Site logo-horizontal DigitalOcean Community Menu Tutorials Questions Projects Meetups Main Site Sign Up Log In submit View All Results By: dinhhoangviet Subscribe Subscribed Share 0 Syntax error near unexpected token `done' May 18, 2014 5.3k views Hi all, Sorry for a noob question, I'm jus started with Linux today :D My droplet used CentOS 6.5. I have a script name "loop.sh" with this code: #!/bin/bash while : do sl done When I try to run it with command "bash loop.sh" there's error: syntax error near unexpected token `done'. What can I do now? Please help. Thank you so much. Log In to Comment Leave a Comment Add comments here to get more clarity or context around a question. To answer a question, use the “Answer” field below. Log In to Comment 4 Answers 0 sianios May 18, 2014 Replace : with ; See here for more examples http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO-7.html Reply Log In to Comment 0 dinhhoangviet May 18, 2014 I replaced : with ; then got another error syntax error near unexpected token `;' Reply Log In to Comment 0 sianios May 18, 2014 You need a condition for the while loop. See the examples in the link I gave you above. Reply Log In to Comment 0 dinhhoangviet May 18, 2014 I copied and created new file with the code in example of the link: #!/bin/bash COUNTER=0 while [ $COUNTER -lt 10 ]; do echo The counter is $COUNTER let COUNTER=COUNTER+1 done Nothing changed! There's error: line 6: syntax error near unexpected token `done' Why bash programing is too hard??? Reply Log In to Comment Have another answer? Share your knowledge. Log In to Answer Copyright © 2016 DigitalOcean™ Inc. Community Tutorials Questions Projects Tags Newsletter RSS Distros & One-Click Apps Terms, Privacy, & Copyright Security Report a Bug Get Paid to Write Almost there! Sign into your account, or create a new one, to start interactingBash Syntax Error Near Unexpected Token Fi'