小编Pow*_*wea的帖子

Bash 脚本:检查文件是否为文本文件

我正在编写一个基于菜单的 bash 脚本,其中一个菜单选项是发送带有文本文件附件的电子邮件。我在检查我的文件是否为文本文件时遇到问题。这是我所拥有的:

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
Run Code Online (Sandbox Code Playgroud)

我不断收到错误消息:分隔符必须是单个字符。

shell scripting bash file-command

6
推荐指数
3
解决办法
1万
查看次数

标签 统计

bash ×1

file-command ×1

scripting ×1

shell ×1