I know this topic has been already covered (somehow here and also somewhere else) but I beg you indulgence because I'm trying to find my way through the bash scripting art;
I need to sort out the following problem
given that I have:
dir1
- file 1
- file 2
- and so on...
dir2
- file1
- file2
- and so on...
I want to rename files so that
dir1
- dir1_file 1
- dir1_file 2
- dir1_and so on...
dir2
- dir2_file1
- dir2_file2
- dir2_and so on...
so far I've managed to work out the following "exploratory" bash script
for d in `ls -d */`
do
#echo "$d"
pre="${d:0:-1}"
#echo "$pre"
#cd "${d}"
pushd "${d}"
for f in *.jp2
do
#echo "${f}"
echo "${pre}_${f}"
done
#cd -
#popd
done
it's seems working (quite) fine except that of the error message
line 9: pushd: dir2/: No such file or directory
where dir2 is the name of last dir being swept by the for loop...
any help for that? what I'm missing?