1

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

2 Answers 2

5

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
Sign up to request clarification or add additional context in comments.

2 Comments

thanks! a lot of the articles online were really unclear, this helped a lot!
sh and bash are kind of awkward and ugly. Almost wish ruby was the standard scripting language on OSes 8-}
3

you can check your script for these type of errors at

http://www.shellcheck.net/

i generally use this for spotting my errors.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.