Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR SHELL

bash assign array to variable

#create array:  or for int..  myArray=(1 2 3 4 5)
declare -a myArray=("cat" "dog" "mouse" "frog")
#to copy array instead of referencing aka array.slice(0)
declare -a myNewArray=("${myArray[@]}")
#slice array: returns ("cat" "dog")
declare -a myFirstHalf=( "${array[@]:0:2}" )
Source by www.freecodecamp.org #
 
PREVIOUS NEXT
Tagged: #bash #assign #array #variable
ADD COMMENT
Topic
Name
1+7 =