linux - 意外标记附近的语法错误 `if'

标签 linux bash ubuntu if-statement scripting

我目前正在尝试编写一个 bash 脚本,它可以帮助我单步执行目录并检查文件的 .jpeg 或 .jpg 扩展名。我想出了以下内容:

#declare $PICPATH, etc...

for file in $PICPATH
    if [ ${file -5} == ".jpeg" -o ${file -4} == ".jpg" ];
    then
        #do some exif related stuff here.
    else
        #throw some errors
    fi
done

执行时,bash 不断在 if 行上抛出错误:“意外标记 ‘if’ 附近的语法错误。

我完全不熟悉脚本;我的 if 语句有什么问题?

谢谢。

最佳答案

我认为您只是缺少 for 循环的 do 子句:

#declare $PICPATH, etc...

for file in $PICPATH; do
    if [ ${file -5} == ".jpeg" -o ${file -4} == ".jpg" ];
    then
        #do some exif related stuff here.
    else
        #throw some errors
    fi
done

关于linux - 意外标记附近的语法错误 `if',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14541501/

相关文章:

c++ - '错误 : expected a type' creating a new instance

Linux Lubuntu Eclipse Checkstyle SWT 错误

ubuntu - 安装 Debian 软件包时禁用提示

php - 在/usr 下找不到 libmysqlclient。在 Ubuntu 12.4 上从源代码构建 PHP 5.2

bash - OCI 运行时创建失败 : container_linux. go:380

Linux 用户空间 PCI 驱动程序

c++ - QProcess 输出不显示

bash - 将字符串作为参数发送到 bash 脚本,以使用 Git Alias 自动执行 Git 命令

linux - grep/根据第一个文件中的列表从第二个文件中获取字符串

linux - Bash 在使用 cat 找不到参数时打印帮助消息