I have very little understanding of bash scripting. I need to recurse through a folder and its subfolders, identify png files, pass them to an external linux application and capture the output of that application in a text file with the text file's first name being same as the file that was passed to the external program. Also the txt file has to be created in the same folder as the png file.
After searching through SO and googling I have come up with the following script
#!/bin/sh
cd folder1/folder2
find . -maxdepth 4 -iname '*.png' -type f |while read line; do
fullfilename="${line##*/}";
base="${fullfilename%.*}";
ext="${fullfilename##*.}";
mypath="${line%/*}";
#echo $fullfilename;
#echo $base;
#echo $ext;
#echo $mypath;
#echo $mypath/$base.txt;
#echo $line;
myexternalprogram -x $line > $mypath/$base.txt;
# -x is a switch reqd by the external program
done
Several of the subfolders of folder2 have white spaces in their names e.g. Sub Folder 12
Running the above gives an error
...line 16: $mypath/$base.txt. ambigous redirect
Just to check i removed the redirect portion on line 16. I got the error
./subfolder1/subfolder2/Sub is an unknown extension
thrown by myexternal program obviously because it stuck at the white spaces in subfolder name.
Can anyone help me out please? What am I doing wrong?