0

I want to copy folder M0R0 to M1R0, M1R1, M1R2, etc.

echo -n "M= "
read m
echo -n "From run= "
read r1
echo -n "To run= "
read r2

for i in $(seq $r1 $r2)
do
        echo "M$mR$i"
        cp -rp M0R0 M$mR$i
done

However this code ignores the second variable $i and it only creates directory M1

codeforester
  • 34,080
  • 14
  • 96
  • 122
ASE
  • 1,312
  • 2
  • 18
  • 23
  • The problem should be with the `$m` variable. You're trying to use `$mR` instead. – Barmar Oct 26 '18 at 23:03
  • When you want to loop after both `Mx` and `Rx`, you should have a second loop inside the first one. `for ((m=0;m,10;m++)); do for i=0;i<5;i++)); do ..done;done` – Walter A Oct 27 '18 at 20:34
  • The answer you are referring to is good for the one who already know the answer to this question. – ASE Oct 28 '18 at 07:39

1 Answers1

1

You really don't need to use sequences. Also, when using substitution use ${} to indicate where the variable to be substituted.

echo -n "M= "
read m
echo -n "From run= "
read r1
echo -n "To run= "
read r2

for ((i=$r1; i <=$r2; ++i));
do
        echo "M${m}R${i}"
        cp -rp M0R0 "M${m}R${i}"
done
apatniv
  • 1,543
  • 9
  • 12