小编Eur*_*opa的帖子

仅从文件中提取我的 --mime-type 以在 bash 脚本中的 if-else 中使用

我发现这个命令给了我一个文件中的 mime 类型:

file --mime-type dog.jpeg 
Run Code Online (Sandbox Code Playgroud)

输出:

dog.jpeg: image/jpeg
Run Code Online (Sandbox Code Playgroud)

我现在正在尝试创建一个 bash 检查 mime 是否是 jpeg og png。但是我有点卡住了:

#!/bin/bash
$file_mime="file --mime-type dog.jpeg"
mime=`"${file_mime#*:}"`

if(mime=='image/jpg' OR mime=='image/png') do:
    echo"Jpg or png"
done
Run Code Online (Sandbox Code Playgroud)

输出:

./bash.sh: line 2: =file --mime-type dog.jpeg: command not found
./bash.sh: line 3: : command not found
Run Code Online (Sandbox Code Playgroud)

bash 20.10

2
推荐指数
1
解决办法
175
查看次数

标签 统计

20.10 ×1

bash ×1