In my program, I want to get substrings of the inputs to compare them and save them as variables however my script seems to be freezing/stuck in a loop.
#!/bin/bash
ram="5G";
file="forge.jar"
dir="MC/Eternal/"
echo $@
for var in $@
do
begin= `awk -v awkvar="$var" '{print substr($awkvar,1,2)}'`
end= `awk -v awkvar="$var" '{print substr($awkvar,3)}'`
echo $begin $end
if [ $begin = "-r" ]
then
echo Setting ram to $end
ram=$end
elif [ $begin = "-d" ]
then
echo "Looking for directory MC/$out"
directory=$end
elif [ $begin = "-f" ]
then
echo "Looking for file $out"
file=$end
fi
done
echo running command: java -Xms1G -Xmx$ram -jar $dir$file
echo Do you want to run it? [Y/n]:
read input
if [ input = "y" ]
java -Xms1G -Xmx$ram -jar $dir$file
else
echo cancelled
fi
When I input ./runserver.sh -r10G -dfoo -fmc.jar
I expect to get java -Xms1G -Xmx10G -jar MC/foo/mc.jar ...
but the program seems to get stuck on the begin= ...
line. I've tried begin = awk '{print substr($awkvar,1,2)}
and just begin = awk '{substr($awkvar,1,2)}'
with the backticks around the awk
statement. I am new to Linux and I have just successfully launched and connected to my Minecraft server. Any and all help is appreciated.
Edit: Found that if I use the "${var:x:y}"
instead of the awk
function I can get a substring. However, it seems that the program is trying to run the arguments instead of making it a string by the error it gives me ./runserver.sh: line 11: -r: command not found