Can anyone please guide me to pass the values for an array during runtime and use it.
I am using Linux OS.
what I am trying to do is, i am trying to pass the output of the ls <source folder> command to a array and copy the list of files in the array to a different (Destination) folder.
It is a common mistake of beginning shell programmers to abuse arrays as the solution to all problems. "Enumerate the universe, shoehorn into shell variable, force-feed into command" is a poor habit, sub-optimal, prone to many pitfalls and corner cases, and generally unnecessary.
Do you actually need an array here? Why not cp -r ?
Two comments:
The shebang indicates you're using sh which doesn't offer arrays. Use e.g. bash or ksh .
There's no array definition command, just a variable assignment. In bash , try a=($(ls)) .