Search code examples
bashexecuteterminatexterm

run xterm -e without terminating


I want to run xterm -e file.sh without terminating.

In the file, I'm sending commands to the background and when the script is done, they are still not finished.

What I'm doing currently is:

(cd /myfolder; /xterm -ls -geometry 115x65 -sb -sl 1000) 

and then after the window pops up

sh file.sh
exit

What I want to do is something like:

(cd /myfolder; /xterm -ls -geometry 115x65 -sb -sl 1000 -e sh file.sh)

without terminating and wait until the commands in the background finish.

Anyone know how to do that?


Solution

  • Use the wait built-in in you shell script. It'll wait until all the background jobs are finished.

    Working Example:

    #!/bin/bash
    # Script to show usage of wait
    sleep 20 &
    sleep 20 &
    sleep 20 &
    sleep 20 &
    sleep 20 &
    wait
    

    The output

    sgulati@maverick:~$ bash test.sh
    [1]   Done                    sleep 20
    [2]   Done                    sleep 20
    [3]   Done                    sleep 20
    [4]-  Done                    sleep 20
    [5]+  Done                    sleep 20
    sgulati@maverick:~$