run xterm -e without terminating

耗尽温柔 提交于 2019-12-30 08:00:48

问题


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?


回答1:


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:~$ 



回答2:


Use hold option:

xterm -hold -e file.sh

-hold Turn on the hold resource, i.e., xterm will not immediately destroy its window when the shell command completes. It will wait until you use the window manager to destroy/kill the window, or if you use the menu entries that send a signal, e.g., HUP or KILL.




回答3:


I tried -hold, and it leaves xterm in an unresponsive state that requires closing through non-standard means (the window manager, a kill command). If you would rather have an open shell from which you can exit, try adding that shell to the end of your command:

xterm -e "cd /etc; bash"

I came across the answer on Super User.




回答4:


Building on a previoius answer, if you specify $SHELL instead of bash, it will use the users preferred shell.

xterm -e "cd /etc; $SHELL"


来源:https://stackoverflow.com/questions/10845372/run-xterm-e-without-terminating

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!