On Thu, 21 Oct 2010, John Kennedy wrote:
Damn...I will get this right...Need more sleep...
for i in `ls -d /opt/* | cut -d/ -f3` do cp /opt/${i}/test/ /backup/${i} done
Using ls in a for loop is rarely necessary.
for i in /opt/*; do cp -a ${i}/test /backup/$(basename $i) done
More simply, just cd to /opt before globbing filenames:
cd /opt for d in *; do cp -a ${i}/test /backup/${i} done