bash - bash 脚本中意外标记 `do' 附近出现语法错误

标签 bash unix ffmpeg

我有一个 bash 脚本,它从命令行获取 3 个参数。它比较目录中的所有文件,看它们是否属于前 2 个参数的类型。如果是,脚本会使用 FFMPEG 命令将此类文件转换为第三个参数的类型。我将使用以下命令执行脚本:

./convert.sh .avi .mp4 .flv 

也就是说,这个脚本会将所有 .avi 和 .mp4 文件转换为 .flv。

当我运行脚本时,出现错误

syntax error near unexpected token `do' in bash script.

代码如下:

#!/bin/bash

# $1 is the first parameter passed
# $2 is the second parameter passed 
# $3 is the third parameter passed

for file in *.*; 
    do 
        #comparing the file types in the directory to the first 2 parameters passed
        if[  ( ${file: -4} == "$1" ) || ( ${file: -4 } == "$2" )  ]{
            export extension=${file: -4}
            #converting such files to the type of the first parameter using the FFMPEG comand
            do ffmpeg -i "$file" "${file%.extension}"$3;
done

最佳答案

对我来说,这是由于CRLF。对于 linux 环境,它应该是 LF

关于bash - bash 脚本中意外标记 `do' 附近出现语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37151619/

相关文章:

mysql - 从其他脚本调用时,Linux 脚本和 MySql 操作不起作用

linux - 如何在mysql中使用myisam引擎优化包含10亿行、固定行格式的表?

c++ - 使用 libavformat 不播放的 H.264 混合到 MP4

bash - 使用 xargs 打印不良视频文件

linux - 如何在python中编写一个可以打开一个新的linux终端并自动执行源代码的脚本

linux - 使用 args 从分隔文件中捕获列

bash - 如何在 Bash 中引用名称中具有不同数字的数组?

java - Unix 中的 Chrome Headless 返回空页面源

docker - 在内部进程崩溃时重新启动 Docker 容器

ffmpeg - 使用 ffmpeg 从电影文件创建的 GIF 尺寸非常大