简体   繁体   English

我的bash脚本中出现“意外令牌'fi'附近的语法错误”

[英]Getting “syntax error near unexpected token `fi'” in my bash script

I'm pretty sure I have an issue with my syntax. 我很确定我的语法有问题。 I've made a simple if/ifthen script, but it hasn't executed. 我编写了一个简单的if / ifthen脚本,但尚未执行。 I can't find anything online about it, because I don't know exactly what the issue is. 我无法在网上找到任何有关它的信息,因为我不知道到底是什么问题。

After fixing most of the problems I'm left with this output: 解决了大多数问题之后,我得到了以下输出:

/media/satahd/media/test.sh: line 21: syntax error near unexpected token `fi'
/media/satahd/media/test.sh: line 21: `fi'

here's the script: 这是脚本:

#!/bin/bash

###root symlink folder:
rootmedia='/media/satahd/media/slinktest'

###root donwload folder:
rootdownload='/media/satahd/media/downloads'
TR_TORRENT_NAME=$1
TR_TORRENT_DIR=$2

anime=$rootdownload'/anime'
movie=$rootdownload'/movies'
western=$rootdownload'/western'

if [ $TR_TORRENT_DIR == $anime ] then
    filebot --action symlink --conflict skip --db AniDB --format "{n} ({y})/{n} {s00e00} {t}({group} {vf})" -r -rename $anime/$TR_TORRENT_NAME non-strict --output $rootmedia/Shows/Anime --order absolute
elseif [ $TR_TORRENT_DIR == $movie ] then
    filebot --action symlink --conflict skip --db themoviedb --format "{n} ({y})/{n} ({y}) {group} {vc}-{vf} {ac}-{af}" -r -rename $movie/$TR_TORRENT_NAME -non-strict --output $rootmedia/Movies
elseif [ $TR_TORRENT_DIR == $western ] then
    filebot --action symlink --conflict skip --db thetvdb --format "{n} ({y})/{n} {s00e00} {t}({group} {vf})" -r -rename $western/$TR_TORRENT_NAME non-strict --output $rootmedia/Shows/Western --order absolute
fi

Why don't you try using elif , not elseif . 为什么不尝试使用elif而不是elseif

Also put a ; 还放一个; before the then. 在那之前。

When you put then on the same line as the if , you need the ; 当将thenif放在同一行时,您需要; delimiter. 定界符。 You don't need it if then is on the next line. 你不需要它,如果then是下一行。

Same thing with for *condition* ; do for *condition* ; do for *condition* ; do If do is on the same line as for , you need the ; for *condition* ; do如果do是在同一行for ,你需要的; otherwise you don't. 否则你不会。

This might work better for you, I corrected just the things I mentioned, but obviously it would be something I couldn't easily test myself. 我更正了我提到的内容,但是这可能对您更有效,但是显然这是我无法轻松测试自己的事情。

#!/bin/bash

###root symlink folder:
rootmedia='/media/satahd/media/slinktest'

###root donwload folder:
rootdownload='/media/satahd/media/downloads'
TR_TORRENT_NAME=$1
TR_TORRENT_DIR=$2

anime=$rootdownload'/anime'
movie=$rootdownload'/movies'
western=$rootdownload'/western'

if [ $TR_TORRENT_DIR == $anime ]; then
    filebot --action symlink --conflict skip --db AniDB --format "{n} ({y})/{n} {s00e00} {t}({group} {vf})" -r -rename $anime/$TR_TORRENT_NAME non-strict --output $rootmedia/Shows/Anime --order absolute
elif [ $TR_TORRENT_DIR == $movie ]; then
    filebot --action symlink --conflict skip --db themoviedb --format "{n} ({y})/{n} ({y}) {group} {vc}-{vf} {ac}-{af}" -r -rename $movie/$TR_TORRENT_NAME -non-strict --output $rootmedia/Movies
elif [ $TR_TORRENT_DIR == $western ]; then
    filebot --action symlink --conflict skip --db thetvdb --format "{n} ({y})/{n} {s00e00} {t}({group} {vf})" -r -rename $western/$TR_TORRENT_NAME non-strict --output $rootmedia/Shows/Western --order absolute
fi

you can check your script for these type of errors at 您可以在以下位置检查脚本中是否存在此类错误

http://www.shellcheck.net/ http://www.shellcheck.net/

i generally use this for spotting my errors. 我通常用它来发现我的错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM