I am writing a menu based bash script, one of the menu options is to send an email with a text file attachment. I am having trouble with checking if my file is a text file. Here is what I have:
fileExists=10
until [ $fileExists -eq 9 ]
do
echo "Please enter the name of the file you want to attach: "
read attachment
isFile=$(file $attachment | cut -d\ -f2)
if [[ $isFile = "ASCII" ]]
then
fileExists=0
else
echo "$attachment is not a text file, please use a different file"
fi
done
I keep getting the error cut: delimiter must be a single character.
-d\
. – Michael Homer Jun 11 '15 at 09:34file
version you have available you should consider using some options like--brief
(which doesn't output the filename so you will have less of a problem with filenames that contain spaces) or--mime
which returns the MIME type (e.g.text/plain
) instead of a textual description of the file type. – Dubu Jun 11 '15 at 10:00