bash 在不终止的情况下运行 xterm -e
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10845372/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
run xterm -e without terminating
提问by jarhead
I want to run xterm -e file.sh without terminating.
我想在不终止的情况下运行 xterm -e file.sh。
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?
有谁知道怎么做?
采纳答案by Samveen
Use the wait
built-in in you shell script. It'll wait until all the background jobs are finished.
使用wait
内置的 shell 脚本。它将等到所有后台作业完成。
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:~$
回答by imwilsonxu
Use hold
option:
使用hold
选项:
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.
-hold 打开保持资源,即当 shell 命令完成时,xterm 不会立即销毁它的窗口。它将等到您使用窗口管理器销毁/终止窗口,或者如果您使用发送信号的菜单项,例如 HUP 或 KILL。
回答by Gid
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:
我尝试了 -hold,它使 xterm 处于无响应状态,需要通过非标准方式(窗口管理器、kill 命令)关闭。如果您希望有一个可以退出的打开的 shell,请尝试将该 shell 添加到命令的末尾:
xterm -e "cd /etc; bash"
I came across the answer on Super User.
我在Super User上找到了答案。
回答by Dan
Building on a previoius answer, if you specify $SHELL instead of bash, it will use the users preferred shell.
基于以前的答案,如果您指定 $SHELL 而不是 bash,它将使用用户首选的 shell。
xterm -e "cd /etc; $SHELL"