greasysock
greasysock

Reputation: 35

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. 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

Upvotes: 1

Views: 2096

Answers (2)

Ashish Srivastava
Ashish Srivastava

Reputation: 101

you can check your script for these type of errors at

http://www.shellcheck.net/

i generally use this for spotting my errors.

Upvotes: 3

clearlight
clearlight

Reputation: 12625

Why don't you try using elif, not elseif.

Also put a ; before the then.

When you put then on the same line as the if, you need the ; delimiter. You don't need it if then is on the next line.

Same thing with for *condition* ; do If do is on the same line as for, you need the ; 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

Upvotes: 5

Related Questions