1

I have a script with case, functions and if statements. Then I want to create an option that when the user press the enter button it starts the script right at the top.

This what I have done:

read -p "Enter to continue" enter

key=$(~/folder/script)

if [[ $enter = "" ]]; then

          $key
else

         echo "Wrong key!"
fi
1
  • 1
    Sounds a bit like a homework assignment... here's a tip for you: you'll probably want to create a loop. It can be an infinite loop with a specific command to break out of it if the user chooses an "exit" option.
    – telcoM
    Jan 2 '19 at 9:59
1

Bash assumed, simply: exec $0.

  • $0 evaluates to the full script path.
  • exec will launch the script, replacing the current instance with a new one.

When placed after echo "Wrong key!", exec $0 will restart the script, which will prompt for new input.

For exec reference, see bash documentation:
https://www.gnu.org/software/bash/manual/bashref.html#index-exec

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.