Iterate through folders with names like folder0100, folder0101 to folder1100 in shell script
Using seq:
for i in $(seq -w 0 1100); do cp test$i/test.out executables/test$i.outdone
with the -w
flag seq pads generated numbers with leading zeros such that all numbers have equal length.
How about this -
#!/bin/bashfor (( i = 0; i < 1100; i++))do cp test$(printf "%04d" $i)/test.out executables/test$(printf "%04d" $i).outdone
With a recent bash
#!/bin/bashfor i in {0000..1100}; dodo cp test$i/test.out executables/test$i.outdone
Note that brace expansion occurs before variable expansion (see the manual) so if you want to do
start=0000stop=1100for i in {$start..$stop}
that won't work. In that case, use seq