The filename suffix after the final dot may be had with ${file##*.}.
In this case though, I would consider doing the uncompressing and the uuencoding with find -exec directly like this:
#!/bin/sh
dir=/home/as1234/bills
find "$dir" -type f -ctime -1 -name "Sum*.pdf*" -exec sh -c '
for pathname do
filename=$( basename "${pathname%.pdf*}.pdf" )
if [ "${pathname##*.}" = "Z" ]; then
uncompress -c "$pathname"
elif [ "${pathname##*.}" = "gz" ]; then
gzip -cd "$pathname"
else
cat "$pathname"
fi |
uuencode "$filename" |
mailx -s "subject ($filename)" [email protected]
done' sh {} +
This way, you would support pathnames with spaces and other troublesome characters. The sh -c script also does not store the uncompressed files but uncompresses them, uuencodes them and sends them in one go.
I also added handling of gzip-compressed files.
Related:
Alternative implementation of the sh -c script using case ... esac instead of multiple if and elif statements.
find "$dir" -type f -ctime -1 -name "Sum*.pdf*" -exec sh -c '
for pathname do
filename=$( basename "${pathname%.pdf*}.pdf" )
case $pathname in
*.Z) uncompress -c "$pathname" ;;
*.gz) gzip -cd "$pathname" ;;
*) cat "$pathname"
esac |
uuencode "$filename" |
mailx -s "subject ($filename)" [email protected]
done' sh {} +