2

Issue Summary: My script works as it should when typed into the terminal, however, it does not work correctly when executed in terminal from a .sh file, why is this?

Script:

echo World of Clucky - Frisnuk "\033]0;Frisnuk - World of Clucky\a"
#! /usr/bin/env bash
BINDIR="$(dirname "$(readlink -fn "$0")")"
cd "$BINDIR"
while true
do
source /home/clucky/MinecraftServers/Frisnuk/serverconfig/config.sh
#Start Server
    java -Xms2000M -Xmx2000M -jar $serverjar.jar nogui
    if [ "`date +%w%H`" = "001" ]
    then
#Delete map files for The End
    rm -R /Frisnuk_the_end
    echo "End has been successfully reloaded"
    echo "[`date +%D\ %T`] End Reloaded" >> /home/clucky/MinecraftServers/Frisnuk/EndRestart.txt
#Change Item of The Week
    weekofyear=`date +%y\-%U`
    s=$(<serverconfig/ItemofTheWeek/item$weekofyear.txt)
    set -- $s
    itemoftheweekid=$2
    itemoftheweekprice=$3
    xmlstarlet edit -L -u "/scs-shop/itemStack[@type='double']" -v $itemoftheweekid /plugins/ShowCaseStandalone/ffs-storage/ffss_cac8480951254352116d5255e795006252d404d8
    xmlstarlet edit -L -u "/scs-shop/price[@type='double']" -v $itemoftheweekprice /plugins/ShowCaseStandalone/ffs-storage/ffss_cac8480951254352116d5255e795006252d404d8
fi
echo "If you want to stop the restart and shut the server off instead, please press Ctrl+C at this time"
for i in 5 4 3 2 1
do
    echo "$i..."
    sleep 1
done
echo "Restarting Server"
clear
done

Instead of working and running the server, it just says this:

World of Clucky - Frisnuk 
/home/clucky/MinecraftServers/Frisnuk/craftminecraft.sh: 7: /home/clucky/MinecraftServers/Frisnuk/craftminecraft.sh: source: not found

Error: Unable to access jarfile .jar
If you want to stop the restart and shut the server off instead, please press Ctrl+C at this time
5...
4...
3...
2...
1...

I am going to take a shower shortly, but I will be returning either later tonight, or tomorrow morning. Thank you in advanced for your assistance.

3
  • The source can be found in the terminal, but not in the script. The file location is correct, as I just copy and paste this script into the terminal window and it works. Commented Nov 17, 2012 at 2:38
  • The script doesn't define the $serverjar variable anywhere. Maybe you have it defined in your environment? Commented Nov 17, 2012 at 2:41
  • the $serverjar is defined in the script that it is sourcing. Commented Nov 17, 2012 at 2:51

1 Answer 1

9

You put an echo before the shebang, so your script is being interpreted by dash, not bash.

dash doesn't include source, because it's not standard.

Correct your shebang and it'll do the trick.


The standard way to source a script is executing it with ..

Instead of source ./myScript.sh, you do . ./myScript.sh. They're the same in bash.

Sign up to request clarification or add additional context in comments.

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.