Search code examples
bashshellshxterm

shell script - open xterm window execute command and keep on executing script


Im writing a shell script and i need my script to open a xterm window run a command and without closing the xterm proceed with the script.

The code is basically a huge case for a menu.

This is an example of my script

...
example() {
echo -n "thingy > "
read thingy
echo -n "thingy1> "
read thingyl
xterm -hold -e *el command*
menux  
}
...

Problem:

The script opens xterm executes the command and keeps the window open but wont continue the script and if i press ctrl + c it goes back to the shell


Solution

  • This change

    nohup xterm -hold -e *el command* &
    

    Will do what you want. The nohup tells the shell not to send the HUP (1) signal to this child process when the parent exits. The & makes the xterm command run in the background so that the script can continue. man nohup has details.

    If you want to do away with the output, then the following will divert all the output to /dev/null and the 2>&1 will make sure that stderr is directed to the same place. If you want to see your errors, then do not perform that second redirection.

    nohup xterm -hold -e *el command* > /dev/null 2>&1 &
    

    man bash has details on redirection.