0

How can I create an array consists of folder names? For example, I have set of folders with names A, B, C, and I want to create the array arr=(A B C).

I tried this:

arr=$(ls ~/Desktop/C\ study/seydtb )

But after that when I create files using this arr

for ((i=0; i<${#arr[@]}; i++)); do
    touch ${arr[$i]}.sey

I get this:

A B C.sey

Only the last one has the .sey suffix.

tripleee
  • 175,061
  • 34
  • 275
  • 318
Olga Ri
  • 17
  • 3

1 Answers1

2

Do not use ls, if you need globbing.

a=(~/Desktop/C\ study/seydtb/*)
for i in "${a[@]}"; do
  echo $i
done
ceving
  • 21,900
  • 13
  • 104
  • 178