I have an older version of bash: 3.2.25 I am trying to write a for loop:
#!/bin/bash
filename="K"
for k in {2..20..2}
do
filename=$filename$k
done
This should give me:
K2
K4
.
.
K20
But this is what it gives me:
K{2..20..2}
K{2..20..2}
.
.
K{2..20..2}
Is it because it is an older version of bash? How can I get it to work? Listing all the values is not a solution because I'm going to have to use {5..201}.
That was added in bash 4, I believe.
You can do:
for (( k=5; k<=201; k+=2 )); do
filename=$filename$k
done
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With