Bash Script Syntax Error Near Unexpected Token Do
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 linux syntax error near unexpected token then' Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation
Linux Syntax Error Near Unexpected Token Newline'
Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just syntax error near unexpected token do for loop like you, helping each other. Join them; it only takes a minute: Sign up syntax error near unexpected token `do' in bash script up vote 0 down vote favorite I have bash script which takes 3 parameters from syntax error near unexpected token do mac the command line. It compares all of the files in the directory to see if they are of the type of the first 2 parameters. If they are, the script converts such files to the type of the third parameter using an FFMPEG command. I would execute the script with the following command: ./convert.sh .avi .mp4 .flv That this, this script would convert all of the .avi and .mp4 files to .flv. When I run
Syntax Error Near Unexpected Token Do R
the script, I get the error syntax error near unexpected token `do' in bash script. Here is the code: #!/bin/bash # $1 is the first parameter passed # $2 is the second parameter passed # $3 is the third parameter passed for file in *.*; do #comparing the file types in the directory to the first 2 parameters passed if[ ( ${file: -4} == "$1" ) || ( ${file: -4 } == "$2" ) ]{ export extension=${file: -4} #converting such files to the type of the first parameter using the FFMPEG comand do ffmpeg -i "$file" "${file%.extension}"$3; done bash unix ffmpeg share|improve this question asked May 11 at 1:30 Avi 145111 1 Test your code with shellcheck –sjsam May 11 at 1:43 I did but I am a beginner in bash. I don't understand some of the error messages well on shellcheck. Any hint of where I went wrong would be greatly appreciated. –Avi May 11 at 1:54 1 To be honest, i can see only the shebang line is correct in this script :| –heemayl May 11 at 1:55 add a comment| 3 Answers 3 active oldest votes up vote 0 down vote accepted You have some issues with your formatting and syntax. sjsam's advice to use shellcheck is good, but the short version is that you s
Wiki Search Tutorials/Articles 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 syntax error unexpected do is for all programming questions. The question does not have to be directly related to syntax error near unexpected token in shell script Linux and any language is fair game. Notices Welcome to LinuxQuestions.org, a friendly and active Linux Community. You are currently viewing LQ as
Unexpected End Of File Bash
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. http://stackoverflow.com/questions/37151619/syntax-error-near-unexpected-token-do-in-bash-script 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 http://www.linuxquestions.org/questions/programming-9/bash-script-problem-syntax-error-near-unexpected-token-%60do-897377/ 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: `do The code is as follows: Code: #!/usr/bin/bash for a in 10 20 30 40 50 60 70 80 90 do for b in 5 15 25 35 45 55 65 75 85 do cp ./a$a/b$b/BoundaryHeatFlux
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta http://unix.stackexchange.com/questions/239139/syntax-error-near-unexpected-token-done-when-looping-a-multi-statement-line 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 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 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 syntax error near file (assume ${tools_urls}, ${tempFolder} 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 th