Bash Syntax Error Unexpected Expecting
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 bash syntax error unexpected token Us Learn more about Stack Overflow the company Business Learn more about hiring developers bash syntax error unexpected end of file or posting ads with us Unix & Linux Questions Tags Users Badges Unanswered Ask Question _ Unix & Linux Stack Exchange syntax error unexpected expecting keyword_end 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 works: Anybody can ask a question
Syntax Error Unexpected Expecting End Syntaxerror
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 article but convenience you can find it here also. ruby syntax error unexpected expecting 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 directly instead of /bin/sh will; correctly use bash instead of dash so that should not be an issue as
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 syntax error ( unexpected bash array Overflow the company Business Learn more about hiring developers or posting ads with us
Syntax Error At Line Unexpected
Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community
Ksh Syntax Error Unexpected
of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up I am getting error “array.sh: 3: array.sh: Syntax error: ”(“ unexpected” up vote 3 down vote http://unix.stackexchange.com/questions/45781/shell-script-fails-syntax-error-unexpected favorite 2 I have written the following code: #!/bin/bash #Simple array array=(1 2 3 4 5) echo ${array[*]} And I am getting error: array.sh: 3: array.sh: Syntax error: "(" unexpected From what I came to know from Google, that this might be due to the fact that Ubuntu is now not taking "#!/bin/bash" by default... but then again I added the line but the error is still coming. Also I have http://stackoverflow.com/questions/25222259/i-am-getting-error-array-sh-3-array-sh-syntax-error-unexpected tried by executing bash array.sh but no luck! It prints blank. My Ubuntu version is: Ubuntu 14.04 arrays bash shell ubuntu share|improve this question edited Aug 9 '14 at 19:46 asked Aug 9 '14 at 19:29 Mistu4u 1,46662352 sh array.sh will generate that error because ordinary bourne shells, such as dash, do not understand arrays. bash array.sh should work fine. I tested your script and, under bash, it works for me. –John1024 Aug 9 '14 at 19:43 @John1024, bash array.sh prints blank in my case. –Mistu4u Aug 9 '14 at 19:45 What does echo $BASH_VERSION say? You may have an old version of bash. –Ned Deily Aug 9 '14 at 19:46 @NedDeily, 4.3.8(1)-release –Mistu4u Aug 9 '14 at 19:47 1 Add set -x after the shebang line. –Ned Deily Aug 9 '14 at 19:57 | show 5 more comments 3 Answers 3 active oldest votes up vote 9 down vote accepted Given that script: #!/bin/bash #Simple array array=(1 2 3 4 5) echo ${array[*]} and assuming: It's in a file in your current directory named array.sh; You've done chmod +x array.sh; You have a sufficiently new version of bash installed in /bin/bash (you report that you have 4.3.8, which is certainly new eno
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 https://ubuntuforums.org/archive/index.php/t-499045.html I get the syntax error. Below is the first lines in the script, line 13 in red. #!/bin/sh # NOTE: # Versions 1.9 (or higher) of aclocal and automake are required. # https://viewsby.wordpress.com/2011/11/16/shell-script-arrays-syntax-error-unexpected/ For Mac OSX users: # Standard distribution usually 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 () syntax error { echo "$@" >&2 exit 1 } ... I already have 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 syntax error unexpected with Ubuntu. When you run it using ./ it will use the shell you mention on first 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
I am using arrays in a script I got the error message as "Shell script arrays Syntax error: "(" unexpected". $ sh arrays.sh #In arrays.sh script I defined some arrays trying to extract values form it The out put I got after running the script is below Shell script arrays Syntax error: "(" unexpected I am struggled a bit to resolve this issue, and the solution I got to know is, most probably in your OS the bash version is updated. So it is unable to resolve the array assignment. To fix the issue use bash instead of using sh while executing the script, that should not throw any syntax error. Example: Run arrays.sh as $ bash arrays.sh -Sany Rate this:Share this:ShareTweetPocketShare on TumblrEmailPrintLike this:Like Loading... Related By Sandeep Posted in bash script, Linux, Shell Scripting 8 Post navigation ← Grep tab inLinux Bash/Shell Script Arrays → 8 comments on “Shell script arrays Syntax error: "("unexpected” Vincent Blouin May 9, 2012 @ 6:36 AM oh my thanks ! Reply Daniel May 22, 2012 @ 9:03 PM Thanks😀 Reply rox January 25, 2013 @ 5:18 PM Merci Reply Vinay February 21, 2013 @ 1:13 PM Thanks ! Reply phuong March 14, 2013 @ 8:54 AM OMG…..thanks very much ^_^ Reply Pingback: pc.casey.jp » 意外な理由(?)で「Shell script arrays Syntax error: “(” unexpected」 jay September 9, 2013 @ 3:32 AM thank you so much .., Reply Harry September 19, 2013 @ 1:19 AM THANKS! Reply Leave a Reply Cancel reply Enter your comment here... Fill in your details below or click an icon to log in: Email (required) (Address never made public) Name (required) Website You are commenting using your WordPress.com account. (LogOut/Change) You are commenting using your Twitter account. (LogOut/Change) You are commenting using your Facebook account. (LogOut/Change) You are commenting using your Google+ account. (LogOut/Change) Cancel Connecting to %s Notify me of new comments via email. Blog Stats 946,932 hits Search Search Follow Blog via Email Enter your email address to follow this blog and receive notifications of new posts by email. Join 59 other followers Recent Posts Quick way to add swap -Ubuntu Get Thread and Heap dump -Java ping ip withport Ubuntu 14.04 - Restore defaults of top bar in gnome sessionfallback Git - create emptybranch Old Posts Old Posts Select Month July 2016 (1) June 2016 (1) December 2015 (2) October 2015 (1) September 2015 (2) August 2015 (1) July 2015 (2) June 2015 (5) May 2015 (4) April 2015 (1) March 2015 (2) February 2015 (4) January 2015 (8) December 2014 (7) November 2014 (6) October 2014 (3) September 2014 (6) August 2014 (3) July 2014 (3) Jun