How to initialize array in shell script?

Wrote a small script to search for scripts in the given folder and running them. When you start swearing in parentheses in the initialization string of the array.
The script itself:
#!/bin/sh

scripts_path="/home/anatoliy/scripts/test/"
scripts_names=( $(ls-a $scripts_path | egrep '\.sh$') )

for i in "${scripts_names[@]}"; do
 echo "=== Start of script $i ==="
 sh $scripts_path$i
 echo "=== End of script $i"
done

Error:
test.sh: 4: test.sh: Syntax error: "(" unexpected
OS: Ubuntu 14.04
July 9th 19 at 10:33
2 answers
July 9th 19 at 10:35
Solved the problem without creating an array in a variable, and performing a search for scripts in.
#!/bin/sh

scripts_path="/home/anatoliy/scripts/test/"

for i in $(ls-a $scripts_path | egrep '\.sh$'); do
 echo "=== Start of script $i ==="
 sh $scripts_path$i
 echo "=== End of script $i"
done

But why do not want to initialize an array in the previous method I did not understand.
So if it is an array, why would you wrap brackets? - mercedes commented on July 9th 19 at 10:38
write
#!/bin/bash
instead
#!/bin/sh
and it will work - laney38 commented on July 9th 19 at 10:41
initially so it was also not working - Landen.Zie commented on July 9th 19 at 10:44
Strange. Maybe it's only in 14.04. In ubuntu 16.04 and Debian running bash, but sh is not working. - laney38 commented on July 9th 19 at 10:47
July 9th 19 at 10:37
Can try code
[guest@localhost ~]$ arr=($(echo -e "a a\nb b\nc c"))
[guest@localhost ~]$ echo ${#arr[@]} ${arr[@]} . ${arr[0]}
6 a a b b c c . a
[guest@localhost ~]$

Find more questions by tags UbuntuLinux