Answers for "assign values to bash array"

5

bash adding to array

#!/bin/bash

#Making an array
array=(1 2 3)

#Appending the array
array+=(4)

#Printing the array
echo ${array[@]}
Posted by: Guest on February-24-2021
0

store command into array bash

#Just use following structure to store output of command into a variable:
var=$(command)
#For example:
var=$(echo 'hi')	#store hi into var
array=($(ls))	#store list of files into var
Posted by: Guest on December-08-2020

Code answers related to "assign values to bash array"

Code answers related to "Shell/Bash"

Browse Popular Code Answers by Language