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.

2

1 Answer 1

2

Do not use ls, if you need globbing.

a=(~/Desktop/C\ study/seydtb/*)
for i in "${a[@]}"; do
  echo $i
done
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.