I have some input element and i want to store them in array . I don't no the limit of element .
Suppose the elements are like
one
two
three
four
five
six
The input size can be different.
i tried it like
declare -a array
read -a array
echo ${array[@]}
but it only print first element. How can i print all values ?
I finally solve it
My code: (https://ideone.com/sy5NQh)
#!/bin/bash
# your code goes here
declare -a array
i=0
while read -r input; do
array[$i]=$input
((i++))
done
echo ${array[@]}
read?read -asplits a single line into an array it doesn't read multiple lines.mapfilehint if you have Bash 4.