【发布时间】:2016-09-06 04:54:25
【问题描述】:
我有 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
【问题讨论】:
-
用shellcheck测试你的代码
-
我做过,但我是 bash 的初学者。我不太了解 shellcheck 上的一些错误消息。任何提示我出错的地方都将不胜感激。
-
说实话,我只能看到这个脚本中的 shebang 行是正确的:|