what would goto, translate to in bash script
This is my code:
#!/bin/bash
read distro </etc/issue
echo $distro
if [[ "$distro" = "Debian GNU/Linux bookworm/sid n l" ]];
then
goto Debian:
elif [[ "$distro" = "Ubuntu GNU/Linux bookworm/sid n l" ]];
then
goto Ubuntu:
elif [[ "$distro" = "kali GNU/Linux bookworm/sid n l" ]];
then
goto Kali:
elif [[ "$distro" = "Arch GNU/Linux bookworm/sid n l" ]];
then
goto Arch:
else
echo No suported OS detected some thing may not work
fi
Debian:
echo using Debian
sleep 5
exit
Ubuntu:
echo using Ubuntu
sleep 5
exit
Kali:
echo using kali
sleep 5
exit
Arch:
echo using Arch
sleep 5
exit
Its a really simple code and I don’t even know if the way I’m checking the Linux distro will work
I have tried with the Goto function from a batch from windows but it wont work on Linux, how would i jump form line to line
2
Answers
I’d recommend using a Switch-Case statement with fall-through.
All the ‘handlers’ can be defined in a function that will be called from the switch:
In this case I’d opt for a more compact
case
statement, eg: