Então, o que no mundo está errado com o meu código?
Para verificar seus scripts de shell, você pode usar o ShellCheck . Aqui está a saída da verificação do seu código:
Vocêestáperdendoalguns
fi
s.Aadiçãodo
fi
sgeraumnovoerro:drivetest()
pareceestarfaltandoumfechamento}
Corrigirissodeixavocêcomalgunsavisos(quedeixareiparavocêcorrigir):
Códigocorrigido:
#!/bin/bashdrivetest(){echo"How much data do you want to write (in MiB):"
read data
echo "Are you sure you want to perform a $data MiB write onto your disk?[Y/N]"
read confirm
if [ "$confirm" == "Y" ]; then
dd bs=1M count=$data if=/dev/zero of=test conv=fdatasync
elif [ "$verify" == "y" ]; then
dd bs=1M count=$data if=/dev/zero of=test conv=fdatasync
else
echo "Exiting the test."
fi
}
stresstest()
{
echo "How long is your stress(tips: Use letters along numbers like s,m,h. If you type number with OUT letter, default as second):"
read time
echo "How many CPU workers do you want?"
read cpu_worker
sudo stress --cpu $cpu_worker --timeout $time
echo ""
echo -e "${yellow}Thermal results:${res}"
sensors
}
random()
{
echo " MENU "
echo "Type 1 for a drive test. "
echo "Type 2 for a stress test. "
echo "Type 3 to perform all tests."
echo "Type other stuffs to exit. "
read value
if [ "$value" == "1" ]; then
drivetest
fi
if [ "$value" == "2" ]; then
stresstest
fi
if [ "$value" == "3" ]; then
{
drivetest
stresstest
}
fi
}
yellow='3[1;33m'
res='3[0m'
echo -e "${yellow}Warning:${res}"
echo -e "${yellow}This script is depended on stress-ng and lm-sensors. Please be sure that you have those package installed.${res}"
echo "Verify [Y/N]:"
read verify
if [ "$verify" == "Y" ]; then
random
elif [ "$verify" == "y" ]; then
random
else
echo -e "${yellow}Please install the dependencies.${res}"
fi
ShellCheck - Uma ferramenta de análise estática de script de shell
ShellCheck is a GPLv3 tool that gives warnings and suggestions for bash/sh shell scripts:
Screenshot of a terminal showing problematic shell script lines highlighted.
The goals of ShellCheck are
To point out and clarify typical beginner's syntax issues that cause a shell to give cryptic error messages.
To point out and clarify typical intermediate level semantic problems that cause a shell to behave strangely and counter-intuitively.
To point out subtle caveats, corner cases and pitfalls that may cause an advanced user's otherwise working script to fail under future circumstances.
Fonte ShellCheck