I am trying to make a check to see if the file being attached to the email is a text file, and if it is not it returns an error. However during testing, I provide a valid text.txt and it returns the "Invalid Attachment" message.
send_email()
{
message=
address=
attachment=
validuser=1
echo "Enter the email address: "
read address
echo ""
getent passwd | grep -q $address
if [ "$?" = "0" ]
then
echo -n "Enter the subject of the message: "
read message
echo ""
echo "Enter the file you want to attach: "
read attachment
attachmenttype='file $attachment | cut -d\ -f2'
if [ $attachmenttype = "ASCII" ]
then
mail -s "$message" "$address"<"$attachment"
press_enter
elif [ $attachmenttype = "cannot" ]
then
mail -s "$message" "$address"<"$attachment"
press_enter
else
echo "Invalid attachment"
press_enter
fi
else
echo "Invalid username"
press_enter
fi
}
cut
command you are using should use the a whitespace as the delimiter, instead of a\
. That is what @sputnick has pointed out. – Sreeraj Dec 10 '14 at 05:51