Ryuzaki
Ryuzaki

Reputation: 1

How can I redirect to a function that is further down in my code?

if [[ $adapter == "1" ]]; then

LINE 66 > usepreferredadapter

elif [[ $adapter == "2" ]]; then

echo -e "\e[0mI'm sorry you do not own the requirements to proceed!"
echo "Try using the adapter that's build in , into your computer (not working on Virtualbox or VMware)"
echo -e "\e[31mNote that build in adapters are over all bad for hacking!\e[0m"
echo "Script will exit!"
exit



else

echo "Invalid input!"
echo "Script will exit!"
exit


fi

LINE 89 > function usepreferredadapter(){

In line 66, I want the user to be redirected to the function in line 89, how can I do that (if it's even possible)?

Upvotes: 0

Views: 56

Answers (2)

ingroxd
ingroxd

Reputation: 1025

In order to avoid this kind of behaviour I suggest you to put all your code in a main function, so that everything is loaded when you need it

E.G.

#!/bin/bash
main() {
  if [[ $adapter == "1" ]]; then
    usepreferredadapter
  elif [[ $adapter == "2" ]]; then
    ...
  fi
}

function usepreferredadapter(){
  ...
}

main "$@"

This way, it doesn't matter where you define your method as long you call the main method at the bottom of your script

Upvotes: 1

haramrit09k
haramrit09k

Reputation: 1

Try shifting the function definition before the line where the function is called, i.e. shift your function definition at line #89 to some place before line #66.

Upvotes: 0

Related Questions