I have a shell script that loops into each directory and finding a file. The problem I have is shell script is unable into cd to a directory that contains space. Here is example script.
First method:
for dir in "$(find /usr/tom/public/junk -maxdepth 3 -type f -name testfile)"; do
cd "$(dirname "$dir")"
printf "%-54s" $(basename $PWD)
done
second method:
find "/usr/tom/public/junk" -maxdepth 3 -type f -name testfile -print |
while IFS= read -r dir
do
cd "$(dirname "$dir")"
printf "%-54s" $(basename $PWD)
done
Error : No such file or directory ( because some directories contains spaces)
my requirement is -> When a "test" file is found in a directory then it has to delete that directory.
I am running this script on ubuntu.And the weird part is, this piece of code working in my Mac but not on ubuntu server. I have no idea why it is not working on ubuntu. Please help me.