Bin/sh Array 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 bin sh 1 syntax error unexpected more about Stack Overflow the company Business Learn more about hiring developers or posting bin sh c line 0 syntax error near unexpected token ads with us Unix & Linux Questions Tags Users Badges Unanswered Ask Question _ Unix & Linux Stack Exchange is a question
Bash Array Syntax Error Near Unexpected Token
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 Anybody can answer The
Syntax Error Unexpected In Shell Script
best answers are voted up and rise to the top `Syntax error: “(” unexpected` when creating an array up 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 bash function 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 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 make
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and
Syntax Error Unexpected Array Php
policies of this site About Us Learn more about Stack Overflow the bash syntax error near unexpected token company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users bash script array 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 http://unix.stackexchange.com/questions/253892/syntax-error-unexpected-when-creating-an-array 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 getting error: array.sh: 3: array.sh: Syntax error: "(" unexpected From what I came to know from Google, that this might be http://stackoverflow.com/questions/25222259/i-am-getting-error-array-sh-3-array-sh-syntax-error-unexpected 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 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 old
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 http://stackoverflow.com/questions/26347650/syntax-error-unexpected-assigning-an-array-in-bash 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 https://forums.linuxmint.com/viewtopic.php?t=124226 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 Syntax error: “(” unexpected assigning an array in syntax error bash up vote 0 down vote favorite Within a bash script, I'm trying to pull all files with an extension '.jstd' into an array, loop over that array and carry out some action. My script is failing to copy the path of each script into the array. I have the following script. #!/bin/bash IFS=$'\n' file_list=($(find '/var/www' -type f -name "*.jstd")) for i in "${file_list[@]}"; do echo "$i" syntax error unexpected done echo $file_list unset IFS The line file_list=($(find '/var/www' -type f -name "*.jstd")) works fine in the terminal, but fails in the script with: Syntax error: "(" unexpected I've googled, but failed. All ideas gratefully received. edit: In case it helps in reproduction or clues, I'm running Ubuntu 12.04, with GNU bash, version 4.2.25(1)-release (i686-pc-linux-gnu) bash share|improve this question edited Oct 13 '14 at 21:02 Charles Duffy 94.5k15102142 asked Oct 13 '14 at 19:40 JonRed 5681125 2 Don't do this. See mywiki.wooledge.org/DontReadLinesWithFor for reasons why. Do this correctly mywiki.wooledge.org/BashFAQ/001 . Also mapfile might be useful here for bash 4+. –Etan Reisner Oct 13 '14 at 19:47 3 That error indicates that you aren't invoking your script with bash. Are you perhaps running sh yourscript? If so, the manual use of sh will override the #!/bin/bash shebang. (Also, allow me to strongly echo the advice given by @EtanReisner; reading from find into an array in this manner is a very lossy process). –Charles Duffy Oct 13 '14 at 20:02 1 ...also, echo $file_list doesn't make sense for an array. printf '%q\n' "${file_list[@]}" would make sense, sure, but as it is your code only prints the first array entry