I am trying to do a script in bash and the idea is that I have an array with text and I use to creat a folder, for example:
#!/bin/bash
dir=(dir1 dir2 dir3)
for i in 0 1 2; do
d=run_${#dir[i]}
echo "Prepare case ${d}..."
done
My problem is that when I do this, it prints:
Prepare case run_4...
Prepare case run_4...
Prepare case run_4...
and the number 4 corresponds to the lenght of each array element, (if I change dir1 to direc1 for example, I get in the first line of the output "Prepare case run_6...")
What i was looking:
Prepare case run_dir1...
Prepare case run_dir2...
Prepare case run_dir3...
What i am missing?
${#? What do you think#means?$idirectly, or at leastd=run_${i}. Good luck.