Home > syntax error > bash array syntax error unexpected expecting

Bash Array 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 Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting bash syntax error unexpected token ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join

Bash Syntax Error Unexpected End Of File

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 syntax error unexpected expecting keyword_end a minute: Sign up I am getting error “array.sh: 3: array.sh: Syntax error: ”(“ unexpected” up vote 3 down vote favorite 2 I have written the following code: #!/bin/bash #Simple array array=(1 2 3 4 5) echo ${array[*]} And I am syntax error unexpected expecting end syntaxerror 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 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

Syntax Error ( Unexpected Bash Array

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 enough); and You execute it correctly then that should work without any problem. If you execute the script by typing ./array.sh the system will pay attention to the #!/bin/bash line and execute the script using /bin/bash. If you execute it by typing something like: sh ./array.sh then it will execute it using /bin/sh. On Ubuntu, /bin/sh is typically a symbolic link to /bin/dash,

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 syntax error unexpected in shell script hiring developers or posting ads with us Unix & Linux Questions Tags Users Badges Unanswered Ask ksh syntax error unexpected Question _ Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join

Syntax Error ( Unexpected Ubuntu

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: “(” unexpected` when creating an array up http://stackoverflow.com/questions/25222259/i-am-getting-error-array-sh-3-array-sh-syntax-error-unexpected vote 1 down vote favorite 1 I have two (Debian) Linux servers. I am creating a shell script. On the first one I create an array thus: #!/bin/bash target_array=( "/home/user/direct/filename -p123 -r" ) That works fine. But when I run this on the other server I get: Syntax error: "(" unexpected As far as I can tell both servers are the same. Can anyone shed some light on why this doesn't work? If I type it into the terminal directly it http://unix.stackexchange.com/questions/253892/syntax-error-unexpected-when-creating-an-array is fine?? It would appear that when I run it as sh scriptname.sh I get the error, but if I run it as ./scriptname.sh it seems to be ok. What's the difference? bash shell-script array share|improve this question edited Jan 7 at 23:36 Gilles 369k666681119 asked Jan 7 at 14:42 IGGt 398213 Did you copy-pasted the script between the two server? try cat -v script to see if there are spurious char. –LilloX Jan 7 at 14:50 2 sh is not bash and so running it as sh scriptname.sh is wrong –Eric Renouf Jan 7 at 15:01 add a comment| 3 Answers 3 active oldest votes up vote 6 down vote accepted When you use ./scriptname.sh it executes with /bin/bash as in the first line with #!. But when you use sh scriptname.sh it executes sh, not bash. The sh shell has no syntax to create arrays, but Bash has the syntax you used. share|improve this answer edited Jan 7 at 23:37 Gilles 369k666681119 answered Jan 7 at 15:06 Konstantin Morenko 1986 OK, that makes sense now. As you can probably tell I'm quite new to Linux (currently trying to convert my Powershell scripts shell/bash scripts). I will stick to using ./ from now on. cheers –IGGt Jan 7 at 15:24 That's not necessarily, but there must be coordination between #!/bin/sh and sh script.sh (or #!/bin/bash and bash script.sh) –Konstantin Morenko Ja

01:57 PMI have seen other threads on this problem, but I didn't find any that posted solutions... When I create a https://ubuntuforums.org/archive/index.php/t-444304.html script and try to use an array like this: #!/bin/bash names=( Jennifer Tonya Anna Sadie ) for name in ${names[@]} do echo $name done I get this error: Syntax https://github.com/mchav/with/issues/15 error: "(" unexpected Pretty much everywhere I look regarding arrays, tells me to create them like I did in the code above. Some of the other posts asked people syntax error to run commands and study the output (again, with no resolution posted), so I will post those here in hopes that someone can help me get to the root of the problem. jon@papa-penguin:~/Desktop$ ls -l /bin/*sh -rwxr-xr-x 1 root root 676836 2006-09-19 15:24 /bin/bash -rwxr-xr-x 1 root root 79912 2006-07-11 12:31 /bin/dash lrwxrwxrwx 1 root root 4 2007-05-13 09:13 syntax error unexpected /bin/rbash -> bash lrwxrwxrwx 1 root root 4 2007-05-13 09:13 /bin/sh -> dash And this is the contents of my /etc/shells file: # /etc/shells: valid login shells /bin/sh /bin/bash Any help would be appreciated. Thanks. QuikeeMay 15th, 2007, 02:27 PMI did my own example and "a=( a b c )" works for me.. however "a= ( a b c )" gives me an error you get. Try to execute with "bash

 

© Copyright 2019|winbytes.org.