Bash Array Syntax Error Word Unexpected Expecting
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might line 1 syntax error word unexpected expecting have Meta Discuss the workings and policies of this site About
Syntax Error Word Unexpected (expecting Do )
Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads
Syntax Error Word Unexpected (expecting ) ) Shell Script
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
Syntax Error Unexpected In Shell Script
programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Syntax error: “(” unexpected (expecting “done”) [duplicate] up vote 2 down vote favorite 1 This question already has an answer here: I am getting error “array.sh: 3: array.sh: Syntax error: ”(“ unexpected” 3 answers I have a very simple syntax error ( unexpected bash array shell script which I'm using to loop through directories, and call another shell script. I wrote it on my local machine (OSX running bash 3.2), and am using it on a remote server running bash 4.2. On the server, when I type which bash, I get /bin/bash, so I added the line on top. I still get this error, pointing to the line that begins arrIN=... 8: run_all_verification.sh: Syntax error: "(" unexpected (expecting "done") The shell script: #!/usr/bin/bash #base name for all experiments BASE_EXP_ID=$1; for i in ${BASE_EXP_ID}* do #split file name by "__" arrIN=(${i//__/ }); EXP_ID=${arrIN[0]} NUM_FEATURES=${arrIN[1]} echo "${EXP_ID} ${NUM_FEATURES}" sh run_verification.sh ${EXP_ID} ${NUM_FEATURES} done bash shell share|improve this question asked Mar 26 '15 at 19:43 Adam_G 1,17652454 marked as duplicate by tripleeebash Users with the bash badge can single-handedly close bash questions as duplicates and reopen them as needed. Dec 14 '15 at 8:32 This question has been asked before and already has an answer. If those answers do not fully
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 ksh syntax error unexpected Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs syntax error ( unexpected ubuntu Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, bash function syntax error unexpected just like you, helping each other. Join them; it only takes a minute: Sign up Bash array: Unexpected Syntax error [closed] up vote 18 down vote favorite 2 I am writing this simple bash script as follows. http://stackoverflow.com/questions/29287474/syntax-error-unexpected-expecting-done #!/bin/bash array=( /home/abc/Downloads/something.bat /home/abc/Downloads/smb.conf ) echo ${array[@]} I expected it to print all the names of the files in the array. But I get this error instead: test.sh: 3: Syntax error: "(" unexpected If I change the declaration of array to array = {/home/abc/Downloads/something.bat /home/abc/Downloads/smb.conf} this error goes away but I still have new errors test.sh: 3: array: not found test.sh: 4: Bad substitution How can I resolve this issue? This is my first time http://stackoverflow.com/questions/11026192/bash-array-unexpected-syntax-error in shell programming so I am unable to fix the issues myself. RESOLVED: I was executing it as sh test.sh but I forgot I had to execute it as bash test.sh arrays bash shell syntax share|improve this question edited Jun 14 '12 at 10:46 Dennis Williamson 167k42235305 asked Jun 14 '12 at 3:17 user1357576 1311211 closed as too localized by Jonathan Leffler, casperOne Jun 14 '12 at 18:58 This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question. 1 That's not an associative array. It's a normal, numerically indexed array. –Dennis Williamson Jun 14 '12 at 3:46 @DennisWilliamson Oh Ok. I will edit it –user1357576 Jun 14 '12 at 3:57 1 @user1357576: Post the solution as an answer and mark it accepted, don't edit it into the question. Also, don't edit the title to resolve it, the website will mark the question as solved when you accept an answer. –Daenyth Jun 14 '12 at 4:01 add a c
Scripting Unix shell scripting - KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and shell scripts and shell scripting languages here. Search Forums Show Threads Show http://www.unix.com/shell-programming-and-scripting/103528-syntax-error-word-unexpected-expecting.html Posts Tag Search Advanced Search Unanswered Threads Find All Thanked Posts Go to Page... linux operating commands and unix operating commands Syntax error: word unexpected (expecting ")") Shell Programming and Scripting Page 1 of 2 1 2 > Thread Tools Search this Thread Display Modes #1 03-05-2009 figaro Registered User Join Date: Jan syntax error 2007 Last Activity: 27 August 2016, 2:57 PM EDT Posts: 842 Thanks: 93 Thanked 29 Times in 25 Posts Syntax error: word unexpected (expecting ")") I have a very simple script that reads in the contents of a file (_open.txt) into an array "lyrics": Code: #!/bin/sh # read in the text lyrics=( `cat _open.txt` | tr '\n' ' ') exit 0 It gives the syntax error word following error message: ./lyrics.sh: 1: Syntax error: word unexpected (expecting ")") I have also tried Code: lyrics=($(cat _open.txt)) as well as with and without quotes (single and double) around the filename. but it yields the same error message. The path /bin/sh is correct. What is the error message really saying? Remove advertisements Sponsored Links figaro View Public Profile Find all posts by figaro #2 03-05-2009 jim mcnamara ...@... Join Date: Feb 2004 Last Activity: 1 October 2016, 1:25 PM EDT Location: NM Posts: 10,825 Thanks: 446 Thanked 968 Times in 899 Posts try this Code: #bash: declare -a lyrics=$( < _open.txt ) #ksh set -A lyrics=$( < _open.txt ) If you are using bash or ksh this will work. ksh limits the number of elements in an array to 1023. So _open.txt has to have less than 1024 "words" in it. Remove advertisements Sponsored Links jim mcnamara View Public Profile Find all posts by jim mcnamara #3 03-05-2009 cfajohnson Shell programmer, author Join Date: Mar 2007 Last Activity: 11 July 2016, 2:55 PM EDT Loc