我有一个 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/