How can I prevent a bash script from closing, so block itself from closing.
Is there a command that executes a command if there is no action?
How can I prevent a bash script from closing, so block itself from closing.
Is there a command that executes a command if there is no action?
From your other (now deleted) question, it seems you want to run
xterm -e your-script
And the terminal emulator window not to go away after the script finishes.
For that, you could add a command that sleeps forever at the end of your script, or in an EXIT trap. See How to do nothing forever in an elegant way? or Is there a Linux command that does nothing, but never exits? for some options.
trap 'sleep infinity' EXIT
Would cause the shell to run sleep infinity
upon exit, and so never exit. With those sleep
implementations that don't support infinity
, replace with a large number, like sleep 2147483647
(the largest 32 bit signed integer which should be safe on most systems and is about 68 years).
With xterm
, you can also use its -hold
option which is designed for that.
gnome-terminal
too; see here: https://askubuntu.com/questions/20330/how-to-run-a-script-without-closing-the-terminal/1209836#1209836.
– Gabriel Staples
Feb 12 '20 at 02:06
Another way of blocking can be using a user input to block. Try using read varname
at the end program so that it will keep waiting for user input and will not exit.
while : ; do done;
anywhere inside your bash script or at the end will prevent a bash script from closing but that'll be of very little use. Can you [edit] your question and provide the current bash script that you're trying to prevent to close? – Fabby Apr 12 '19 at 20:54