Shell Script: correct way to declare an empty array

2013-09-21T00:17:37

I'm trying to declare an empty array in Shell Script but I'm experiencing an error.

#!/bin/bash

list=$@

newlist=()

for l in $list; do

        newlist+=($l)

done

echo "new"
echo $newlist

When I execute it, I get test.sh: 5: test.sh: Syntax error: "(" unexpected

Copyright License:
Author:「luizfzs」,Reproduced under the CC 4.0 BY-SA copyright license with link to original source & disclaimer.
Link to:https://stackoverflow.com/questions/18921350/shell-script-correct-way-to-declare-an-empty-array

About “Shell Script: correct way to declare an empty array” questions

I'm trying to declare an empty array in Shell Script but I'm experiencing an error. #!/bin/bash list=$@ newlist=() for l in $list; do newlist+=($l) done echo "new&q
I am trying to declare an array in my shell script and then have written a for loop to access those array elements into another file. But it is only taking the first element. I've tried the below :
I want to pass associate array as a single argument to shell script. mainshellscript.sh : #!/bin/bash declare -A cmdOptions=( [branch]=testing [directory]=someDir [function1key]=function1value [
Hi I need help to create shell script. let suppose I have below 3 folder location in server but out of 3. 1 or 2 location is correct rest are wrong. I Need to write a shell script to check all 3 fo...
I have a use case like below. declare filterAlias "if [[ $exeteral_variable == true ]]; then echo A; else echo B; fi" A = FOREACH loadData GENERATE a, b, c, d; B = FILTER loadData BY (a==‘xyz’); ...
I need to output the result of this shell script "git diff --name-only commit2 commit1" to an array in groovy. How can I do it? Already tried to create a variable def diff = sh(script: "git diff ...
I tried to declare a Boolean variable in a shell script using the following syntax: variable=$false variable=$true Is this correct? Also, if I wanted to update that variable would I use the same
I want to put below declare in a shell script: proxy_set declare -x https_proxy="https://192.168.220.4:8080/" And then I execute it like below. $ ./proxy_set But "export" shows nothing happened...
There are alot of guides, guides out there which show how to declare and define an array foo[0] = "abc" foo[1] = "def" What i am trying to achieve is to declare an array but not define it becaus...
i have problem to make a dictionary inside a array in shell script so for example with some commands i have two column record zone test07 cname.lan

Copyright License:Reproduced under the CC 4.0 BY-SA copyright license with link to original source & disclaimer.