BASH: how to define an array as environment variable before calling a bash script -


in bash, can do

myvar="somevalue" ./myscript.sh 

and variable myvar defined when running myscript.sh.

my questions is: can same arrays? unfortunately, neither of following works.

myarr=( 1 2 ) ./myscript.sh myarr[0]=1 myarr[1]=2 ./myscript.sh declare -a myarr=( 1 2 ) ./myscript.sh 

incredibility weird.... have never seen before.

it looks array not passed subshell. 1 way around source script instead of executing it:

declare -a myarr=( 1 2 ); . ./myscript.sh 

Comments

Popular posts from this blog

matlab - Deleting rows with specific rules -

jquery - How would i go about shortening this code? And to cancel the previous click on click of new section? -