Bash Function 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 bash syntax error unexpected token this site About Us Learn more about Stack Overflow the company Business bash syntax error unexpected end of file Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask
Syntax Error Unexpected End Of File Bash Script
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 Redirection Unexpected
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: "(" 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 bash syntax error near unexpected token 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 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 se
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
Bash Syntax Error Near Unexpected Token Done'
this site About Us Learn more about Stack Overflow the company Business Learn bash syntax error near unexpected token echo' more about hiring developers or posting ads with us Unix & Linux Questions Tags Users Badges Unanswered Ask Question _ bash syntax error near unexpected token (' ubuntu Unix & Linux Stack Exchange is a 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 http://stackoverflow.com/questions/6347119/bash-syntax-error-unexpected 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: “(” 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 http://unix.stackexchange.com/questions/45781/shell-script-fails-syntax-error-unexpected 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 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 direct
>24.3. Recursion Without Local Variables