This could easily be any lang…but I’m using bash for now. I’m looking for the understanding behind this that can be replicated across langs.
so…
I’m copying a file up the directory tree and than replacing that file with another.
cp "$DIR"/folder2/file2 "$DIR";
mv "$DIR"/folder1/file1 "$DIR"/folder2/file2;
Then I take the copied file and move it into another folder..starting the same dance.
cp "$DIR"/folder3/file3 "$DIR";
mv "$DIR"/file2 "$DIR"/folder3/file3
I want to do this like 100 times+.
what’s the most elegant way?
Elegant, in the sense of brief and understandable by someone else.
You’re trying to:
and so on.
It’s actually easier to do it backwards such that you only need to backup the last file.
Note:
seq $last -1 2generates a sequence of numbers from$lastup to2by increments of-1.seqinstead of brace expansion because the latter doesn’t expand numbers when you have{$last .. 1}