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


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


         echo "Wrong key!"
  • 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

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:

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.