read -a arr
for s in ${arr[@]}; do echo $s; done
arr01=(1 2)
printf -- '- %s\n' "${arr01[@]}"
arr02=(${arr01[@]} 3 4)
printf -- '+ %s\n' "${arr02[@]}"
arr02+=(5 6)
printf -- '- %s\n' "${arr02[@]}"
- 1 - 2 + 1 + 2 + 3 + 4 - 1 - 2 - 3 - 4 - 5 - 6
p=/etc/hosts*
ls $p -ld
echo
arr1=($p)
-rw-r--r-- 1 root root 643 May 5 17:34 /etc/hosts drwxr-xr-x 2 root root 4096 May 21 14:01 /etc/hosts dummyfolder -rw-r--r-- 1 root root 411 Oct 25 2018 /etc/hosts.allow -rw-r--r-- 1 root root 711 Oct 25 2018 /etc/hosts.deny
IFS=' '
echo "${#arr1[@]}"
echo "${arr1[@]}"
echo
for x in "${arr1[@]}"; do echo ">>>$x<<<"; done
echo "--------------"
IFS=$'\n'
echo "${#arr1[@]}"
echo "${arr1[@]}"
echo
for x in "${arr1[@]}"; do echo ">>>$x<<<"; done
4 /etc/hosts /etc/hosts dummyfolder /etc/hosts.allow /etc/hosts.deny >>>/etc/hosts<<< >>>/etc/hosts dummyfolder<<< >>>/etc/hosts.allow<<< >>>/etc/hosts.deny<<< -------------- 4 /etc/hosts /etc/hosts dummyfolder /etc/hosts.allow /etc/hosts.deny >>>/etc/hosts<<< >>>/etc/hosts dummyfolder<<< >>>/etc/hosts.allow<<< >>>/etc/hosts.deny<<<
printf -- '- %s\n' "${arr1[@]}"
- /etc/hosts - /etc/hosts dummyfolder - /etc/hosts.allow - /etc/hosts.deny
arr2=($(printf -- '%s\n' "${arr1[@]}" | grep [.]))
printf -- '%s\n' "${arr2[@]}"
/etc/hosts.allow /etc/hosts.deny
IFS=' '
echo "${#arr1[*]}"
echo "${arr1[*]}"
echo
for x in "${arr1[*]}"; do echo ">>>$x<<<"; done
echo "--------------"
IFS=$'\n'
echo "${#arr1[*]}"
echo "${arr1[*]}"
echo
for x in "${arr1[*]}"; do echo ">>>$x<<<"; done
4 /etc/hosts /etc/hosts dummyfolder /etc/hosts.allow /etc/hosts.deny >>>/etc/hosts /etc/hosts dummyfolder /etc/hosts.allow /etc/hosts.deny<<< -------------- 4 /etc/hosts /etc/hosts dummyfolder /etc/hosts.allow /etc/hosts.deny >>>/etc/hosts /etc/hosts dummyfolder /etc/hosts.allow /etc/hosts.deny<<<
IFS=' '
echo ${#arr1[*]}
echo ${arr1[*]}
echo
for x in ${arr1[*]}; do echo ">>>$x<<<"; done
echo "--------------"
IFS=$'\n'
echo ${#arr1[*]}
echo ${arr1[*]}
echo
for x in ${arr1[*]}; do echo ">>>$x<<<"; done
4 /etc/hosts /etc/hosts dummyfolder /etc/hosts.allow /etc/hosts.deny >>>/etc/hosts<<< >>>/etc/hosts<<< >>>dummyfolder<<< >>>/etc/hosts.allow<<< >>>/etc/hosts.deny<<< -------------- 4 /etc/hosts /etc/hosts dummyfolder /etc/hosts.allow /etc/hosts.deny >>>/etc/hosts<<< >>>/etc/hosts dummyfolder<<< >>>/etc/hosts.allow<<< >>>/etc/hosts.deny<<<
IFS=' '
echo ${#arr1[@]}
echo ${arr1[@]}
echo
for x in ${arr1[@]}; do echo ">>>$x<<<"; done
echo "--------------"
IFS=$'\n'
echo ${#arr1[@]}
echo ${arr1[@]}
echo
for x in ${arr1[@]}; do echo ">>>$x<<<"; done
4 /etc/hosts /etc/hosts dummyfolder /etc/hosts.allow /etc/hosts.deny >>>/etc/hosts<<< >>>/etc/hosts<<< >>>dummyfolder<<< >>>/etc/hosts.allow<<< >>>/etc/hosts.deny<<< -------------- 4 /etc/hosts /etc/hosts dummyfolder /etc/hosts.allow /etc/hosts.deny >>>/etc/hosts<<< >>>/etc/hosts dummyfolder<<< >>>/etc/hosts.allow<<< >>>/etc/hosts.deny<<<
s='''
x "x2 x3"
yy
zzz
'''
IFS=$'\n'
arr=($s)
printf -- '>>>%s<<<\n' "${arr[@]}"
echo "count: " ${#arr[@]}
>>>x "x2 x3"<<< >>>yy<<< >>>zzz<<< count: 3
IFS='
'
arr=($s)
printf -- '>>>%s<<<\n' "${arr[@]}"
echo "count: " ${#arr[*]}
>>>x "x2 x3"<<< >>>yy<<< >>>zzz<<< count: 3
IFS=' '
arr=($s)
printf -- '>>>%s<<<\n' "${arr[@]}"
echo "count: " ${#arr[*]}
>>> x<<< >>>"x2<<< >>>x3" yy zzz <<< count: 3
IFS='\n'
arr=($s)
printf -- '>>>%s<<<\n' "${arr[@]}"
echo "count: " ${#arr[*]}
>>> x "x2 x3" yy zzz <<< count: 1