How to Prompt the user to press Enter to Exit in terminal so that the terminal doesn't close automatically?

5,217

Add at the end of your script:

read junk

See Bash Manual for more info.

Share:
5,217

Related videos on Youtube

Belldandu
Author by

Belldandu

I don't answer questions unless i know the person making the question will benefit from my answer

Updated on September 18, 2022

Comments

  • Belldandu
    Belldandu almost 2 years

    Here is my Port.sh file

    echo 'Give me a maximum of 5 seconds to run please.'
    lsof -i | grep Xvnc | grep ESTABLISHED | grep $USER
    lsof -i | grep $USER | grep Xvnc | grep -o -P '(?<=:).*(?=->)'
    echo 'Brought to you by a cloudy and unlucky day.'
    echo 'Press enter to exit'
    

    I would like to make the terminal wait for the user to press enter after the last echo before closing.

    All of the users on my ubuntu desktop environment have the terminal set to close after the script is done.

    Can anyone tell me what i can do to make the terminal wait for the user to press enter.

    I have google searched and nothing relevant came up.

  • Belldandu
    Belldandu over 9 years
    thats it? nothing else? if so then thanks and i kinda feel stupid x.x
  • Stephen Kitt
    Stephen Kitt over 9 years
    You don't even need junk, read on its own is sufficient.
  • Belldandu
    Belldandu over 9 years
    I thought it would be much harder than that x.x . This is what i get for thinking about it too hard.Thanks guys
  • madneon
    madneon over 9 years
    From Bash manual: If no names are supplied, the line read is assigned to the variable REPLY.
  • Belldandu
    Belldandu over 9 years
    thx @madneon i will be marking this as the answer in 3 minutes