Algo assim funciona bem para mim:
for files in /home/gv/Desktop/PythonTests/*.sh; do
old_filename=$files
old_filename_stripped=$(basename -a $files)
echo "filename full : $old_filename - file name stripped: $old_filename_stripped"
done
saída:
filename full : /home/gv/Desktop/PythonTests/advfind2.sh - file name stripped: advfind2.sh
filename full : /home/gv/Desktop/PythonTests/advfind.sh - file name stripped: advfind.sh
filename full : /home/gv/Desktop/PythonTests/appslist(draft).sh - file name stripped: appslist(draft).sh
filename full : /home/gv/Desktop/PythonTests/appslist.sh - file name stripped: appslist.sh
Código aprimorado para incluir espaços e subdiretórios:
IFS=$'\n'
for files in $(find /home/gv/Desktop/PythonTests/ -name "*.txt" ); do
old_filename="$files"
old_filename_stripped=$(basename -a "$files")
echo "filename full : $old_filename - file name stripped: $old_filename_stripped"
done
unset IFS
Saída:
filename full : /home/gv/Desktop/PythonTests/b.txt - file name stripped: b.txt
filename full : /home/gv/Desktop/PythonTests/c.txt - file name stripped: c.txt
filename full : /home/gv/Desktop/PythonTests/a ver 1.txt - file name stripped: a ver 1.txt
filename full : /home/gv/Desktop/PythonTests/d.txt - file name stripped: d.txt
filename full : /home/gv/Desktop/PythonTests/a.txt - file name stripped: a.txt
filename full : /home/gv/Desktop/PythonTests/appsfiles/a.txt - file name stripped: a.txt
PS: Veja a última linha, é um subdiretório.