Bash Syntax Error Unexpected
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 bash syntax error unexpected token more about hiring developers or posting ads with us Unix & Linux Questions Tags Users Badges bash syntax error unexpected end of file Unanswered Ask Question _ Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like bash array syntax error unexpected 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 Shell script fails: Syntax error: bash syntax error near unexpected token done' “(” unexpected up vote 31 down vote favorite 7 I've been working on a script that automates setting up a development environment for Raspberry Pi development (step by step details that work are here). The script is linked in that article but convenience you can find it here also. Now when run this script install and sets up the environment without error but you have to enter your sudo password more than once due to sudo's time-out value
Bash Syntax Error Near Unexpected Token Echo'
by default. So I started experimenting by removing all the sudo lines and running the whole script via sudo at the command line like so: kemra102@ubuntuvm:~$ sudo ./pi_dev_env_install.sh This works fine as expected and gets most of the way through until this point: ./pi_dev_env_install: 68: ./pi_dev_env_install.sh: Syntax error: "(" unexpected Now this line worked fine previously when not running the whole script with sudo. There is nothing about this line running as sudo that should stop it working to my knowledge, does anyone have any ideas? bash shell ubuntu shell-script share|improve this question edited Aug 18 '12 at 12:08 Gilles 369k666681119 asked Aug 18 '12 at 11:37 kemra102 4681613 The shebang is really in line 9? Due to Ubuntu's DashAsBinSh affinity I suspect your script is interpreted by dash instead of bash. Try to move the shebang in line 1. –manatwork Aug 18 '12 at 11:45 According to that article calling /bin/bash directly instead of /bin/sh will; correctly use bash instead of dash so that should not be an issue as I understand it. I can still move the shebang of course, but that doesn't really explain as to why it works when you don’t sudo the whole script. –kemra102 Aug 18 '12 at 11:50 add a comment| 5 Answers 5 active oldest votes up vote 47 down vote accepted The script does not begin with a shebang
Syntax error: "(" unexpected stigalaJuly 12th, 2007, 09:33 AMHi, I'm trying to run a script on ubuntu 7.04; stig@stig-laptop:~/mosesdecoder$ ./regenerate-makefiles.sh ./regenerate-makefiles.sh: 13: Syntax error: "(" unexpected but then I get the syntax error. Below
Bash Syntax Error Near Unexpected Token (' Ubuntu
is the first lines in the script, line 13 in red. #!/bin/sh # bash syntax error near unexpected token else' NOTE: # Versions 1.9 (or higher) of aclocal and automake are required. # For Mac OSX users: # Standard distribution usually bash syntax error near unexpected token fi' includes versions 1.6. # Get versions 1.9 or higher # Set the following variable to the correct paths #ACLOCAL="/path/to/aclocal-1.9" #AUTOMAKE="/path/to/automake-1.9" function die () { echo "$@" >&2 exit 1 } ... I already have http://unix.stackexchange.com/questions/45781/shell-script-fails-syntax-error-unexpected automake (GNU automake 1.9.6) and aclocal (GNU automake 1.9.6). Setting the paths is only for Mac OSX users, so I didn't try to set any of those paths. Anyone can explain this? Thanks for any help, Stig Rui PaisJuly 12th, 2007, 10:01 AMHi. the (inexistent) problem is the 1st line in combination with Ubuntu. When you run it using ./ it will use the shell you mention on first https://ubuntuforums.org/archive/index.php/t-499045.html line, in your case: #!/bin/sh if you do a ls -l /bin/sh you will see that it's just a link to dash. Ubuntu, since Edgy, replaced old sh with dash, creating a series of incompatibilities in a lot of scripts... So, either you run: bash regenerate-makefiles.sh or replace first line with: #!/bin/bash (or even remove the 1st line and environment will call it with bash) or (losing generality) adapt it for dash: remove the keyword function: die() { ... } hth stigalaJuly 12th, 2007, 10:55 AMThanks a lot, Rui! I used bash regenerate-makefiles.sh and the script ran perfectly. I guess I'll have to read up on dash, bash and sh to understand the difference between the different shells. Stig Rui PaisJuly 12th, 2007, 11:16 AMNo prob :) sh and bash has more or less the same syntax, so usually no problem came from there... but dash is much more different. it's suppose to be much lighter and faster then bash, being that the reason why they choose it by Edgy days. A lot of people had problem, specially with custom scripts. I still have to manually edit some files for use plugins on TeXmacs editor, and they are the officially supported ones :( It wa
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 http://stackoverflow.com/questions/6347119/bash-syntax-error-unexpected hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges http://stackoverflow.com/questions/5134399/bash-syntax-error-near-unexpected-token-newline 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. Join them; it only takes a minute: Sign up bash Syntax error: “(” unexpected up vote 5 down vote favorite 1 For some reason this function is working properly, the terminal is outputting newbootstrap.sh: 2: Syntax error: "(" syntax error unexpected Here is my code (line 2 is function MoveToTarget() {) #!/bin/bash function MoveToTarget() { #This takes to 2 arguments: source and target cp -r -f "$1" "$2" rm -r -f "$1" } function WaitForProcessToEnd() { #This takes 1 argument. The PID to wait for #Unlike the AutoIt version, this sleeps 1 second while [ $(kill -0 "$1") ]; do sleep 1 done } function RunApplication() { #This takes 1 application, the path to the thing to execute bash syntax error exec "$1" } #our main code block pid="$1" SourcePath="$2" DestPath="$3" ToExecute="$4" WaitForProcessToEnd $pid MoveToTarget $SourcePath, $DestPath RunApplication $ToExecute exit linux osx bash scripting syntax-error share|improve this question edited Mar 2 at 20:59 Jens 36.2k863104 asked Jun 14 '11 at 16:50 rsmith 2613 add a comment| 2 Answers 2 active oldest votes up vote 17 down vote You're using the wrong syntax to declare functions. Use this instead: MoveToTarget() { # Function } Or this: function MoveToTarget { # function } But not both. Also, I see that later on you use commas to separate arguments (MoveToTarget $SourcePath, $DestPath). That is also a problem. bash uses spaces to separate arguments, not commas. Remove the comma and you should be golden. share|improve this answer edited Jun 14 '11 at 16:58 answered Jun 14 '11 at 16:52 Rafe Kettler 40.3k12104123 Thanks! It makes sense now. I saw some websites that did that. –rsmith Jun 14 '11 at 16:53 1 @rsmith that website was incorrect, then. –Rafe Kettler Jun 14 '11 at 16:53 @rsmith Name the site or it was a dream :-) –Jens Mar 2 at 21:00 add a comment| up vote 1 down vote I'm also new to defining functions in bash scripts. I'm using a bash of version 4.3.11(1):-release (x86_64-pc-linux-gnu) on Ubuntu 14.04. I don't know why but the definition that starts with the keyword function ne
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 Stack Overflow Questions Jobs Documentation Tags Users Badges 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. Join them; it only takes a minute: Sign up -bash: syntax error near unexpected token `newline' up vote 17 down vote favorite 7 To reset the admin password from SolusVM have i the follow code php /usr/local/solusvm/scripts/pass.php --type=admin --comm=change --username=