[SOLVED] Shell script improvements
by morleyrees from LinuxQuestions.org on (#6QSSN)
Hi,
The following script works - before I create a backup I parse all directories for pdf files and if there are matching doc? or xls? files in the same directory the pdf file will be deleted.
Is there a more 'elegant' way to export the FileType via the -exec? Are there any obvious improvements I could make?
Code:SrcDir='/home/backup/'
# File extensions to check
doc='doc'
docx='docx'
xls='xls'
xlsx='xlsx'
for FileType in $doc $docx $xls $xlsx
do
export FileType
find "$SrcDir" -type f -iname '*.pdf' -exec sh -c "$FileType"'
for pathname do
doc_pathname=${pathname%.pdf}."$FileType"
if [ -f "$doc_pathname" ]; then
echo "$pathname"
rm "$pathname"
fi
done' find-sh {} +
doneThanks,
Mike
The following script works - before I create a backup I parse all directories for pdf files and if there are matching doc? or xls? files in the same directory the pdf file will be deleted.
Is there a more 'elegant' way to export the FileType via the -exec? Are there any obvious improvements I could make?
Code:SrcDir='/home/backup/'
# File extensions to check
doc='doc'
docx='docx'
xls='xls'
xlsx='xlsx'
for FileType in $doc $docx $xls $xlsx
do
export FileType
find "$SrcDir" -type f -iname '*.pdf' -exec sh -c "$FileType"'
for pathname do
doc_pathname=${pathname%.pdf}."$FileType"
if [ -f "$doc_pathname" ]; then
echo "$pathname"
rm "$pathname"
fi
done' find-sh {} +
doneThanks,
Mike