"Mv" command does not work in loop, but works manually

Hi there, this may be a beginner's error, but I've been unable to find a solution on my own and by googling, and now I am really stuck on it.

I am simply trying to move directories called for example CAT_Run01.ica to a directory with the corresponding number, Run01, in the same directory.

For some reason the loop does not work

		nrun=`ls -d CAT_Run??.ica | wc -l`							
		for run in `seq 1 $nrun`; do
			mv CAT_Run0$run.ica Run0$run
                done

The "mv" command works manually: if I instead of looping type "run=1", then the line "mv CAT_Run0$run.ica Run0$run" will work and move "CAT_Run01.ica/" to "Run01/". The sequence works, it prints out the correct numbers.

But for some reason, when running the loop, I get the error:
"-bash: 0.ica: command not found"

Best,
Andreas
Psychology student just trying to work with some data

The file names and the sequence number are not necessarily synchronised; e.g. a single file CAT_Run02 will yield an nrun value of 1 and so the seq will never produce a match. A different approach should be chosen.

Howsoever, this would not explain the error message you saw. Nor can I. Pls run the script again with the -x (xtrace) option set, and post the result.

Perhaps you want

for f in CAT_Run??.ica; do
  test -f "$f" &&
  echo mv "$f" "${f#CAT_}"
done

Important: the arguments to mv (and test) must be in "quotes".