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=1echo Enter the email address: read addressecho getent passwd | grep -q $addressif [ $? = 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_enterelif [ $attachmenttype = cannot ]  then   mail -s $message $address<$attachment  press_enterelse  echo Invalid attachment  press_enterfi else    echo Invalid username    press_enterfi}
Check if a file is a text file in bash
bash;shell;scripting;file command
Instead of attachmenttype='file $attachment | cut -d\  -f2'you should write :attachmenttype=$(file $attachment | cut -d' ' -f2)See http://wiki.bash-hackers.org/syntax/expansion/cmdsubstor to get mime-type :$ file -i $attachmenttype | cut -d' ' -f2text/plain;and decide what you want to do with the file depends of the type.