xterm in bash stops script from executing
I have the following script:
#!/bin/bash
xterm -e ' sh -c "$HOME/TEST/FirstAPP --test;" exec bash'
## script opens the xterm and stops until I press CTRL+C
while true; do
....
this question is related to this question
Why does the script stop at this place? I need to get the xterm called and running and then continue with the code having FirstApp running.
I used the gnome-terminal without problems.
bash scripts xterm
|
show 2 more comments
I have the following script:
#!/bin/bash
xterm -e ' sh -c "$HOME/TEST/FirstAPP --test;" exec bash'
## script opens the xterm and stops until I press CTRL+C
while true; do
....
this question is related to this question
Why does the script stop at this place? I need to get the xterm called and running and then continue with the code having FirstApp running.
I used the gnome-terminal without problems.
bash scripts xterm
1
Where exactly does it stop? And what does FirstApp do? Does it ever exit? How is the terminal when it is "stopped"? Does it display a prompt? Why are you runningexec bash
?
– terdon♦
Feb 5 at 15:49
it starts a process, that does not end, but sometimes fails, so that is why it need to be killed and restartd every hour.
– user1616685
Feb 5 at 16:05
I put exec bash in order to go on with the script
– user1616685
Feb 5 at 16:06
1
But ifFirstAPP
doesn't end, how would anything else continue? Your command means "runFirstAPP
and when that finishes, runexec bash
". If that is not what you want, please edit and clarify what behavior you are expecting. You can also ping me in chat if you want and we can see if we can sort it out.
– terdon♦
Feb 5 at 16:09
1
Have you tried running the terminal in the background?
– wjandrea
Feb 5 at 16:24
|
show 2 more comments
I have the following script:
#!/bin/bash
xterm -e ' sh -c "$HOME/TEST/FirstAPP --test;" exec bash'
## script opens the xterm and stops until I press CTRL+C
while true; do
....
this question is related to this question
Why does the script stop at this place? I need to get the xterm called and running and then continue with the code having FirstApp running.
I used the gnome-terminal without problems.
bash scripts xterm
I have the following script:
#!/bin/bash
xterm -e ' sh -c "$HOME/TEST/FirstAPP --test;" exec bash'
## script opens the xterm and stops until I press CTRL+C
while true; do
....
this question is related to this question
Why does the script stop at this place? I need to get the xterm called and running and then continue with the code having FirstApp running.
I used the gnome-terminal without problems.
bash scripts xterm
bash scripts xterm
edited Feb 5 at 16:13
terdon♦
66.6k12139221
66.6k12139221
asked Feb 5 at 15:24
user1616685user1616685
1155
1155
1
Where exactly does it stop? And what does FirstApp do? Does it ever exit? How is the terminal when it is "stopped"? Does it display a prompt? Why are you runningexec bash
?
– terdon♦
Feb 5 at 15:49
it starts a process, that does not end, but sometimes fails, so that is why it need to be killed and restartd every hour.
– user1616685
Feb 5 at 16:05
I put exec bash in order to go on with the script
– user1616685
Feb 5 at 16:06
1
But ifFirstAPP
doesn't end, how would anything else continue? Your command means "runFirstAPP
and when that finishes, runexec bash
". If that is not what you want, please edit and clarify what behavior you are expecting. You can also ping me in chat if you want and we can see if we can sort it out.
– terdon♦
Feb 5 at 16:09
1
Have you tried running the terminal in the background?
– wjandrea
Feb 5 at 16:24
|
show 2 more comments
1
Where exactly does it stop? And what does FirstApp do? Does it ever exit? How is the terminal when it is "stopped"? Does it display a prompt? Why are you runningexec bash
?
– terdon♦
Feb 5 at 15:49
it starts a process, that does not end, but sometimes fails, so that is why it need to be killed and restartd every hour.
– user1616685
Feb 5 at 16:05
I put exec bash in order to go on with the script
– user1616685
Feb 5 at 16:06
1
But ifFirstAPP
doesn't end, how would anything else continue? Your command means "runFirstAPP
and when that finishes, runexec bash
". If that is not what you want, please edit and clarify what behavior you are expecting. You can also ping me in chat if you want and we can see if we can sort it out.
– terdon♦
Feb 5 at 16:09
1
Have you tried running the terminal in the background?
– wjandrea
Feb 5 at 16:24
1
1
Where exactly does it stop? And what does FirstApp do? Does it ever exit? How is the terminal when it is "stopped"? Does it display a prompt? Why are you running
exec bash
?– terdon♦
Feb 5 at 15:49
Where exactly does it stop? And what does FirstApp do? Does it ever exit? How is the terminal when it is "stopped"? Does it display a prompt? Why are you running
exec bash
?– terdon♦
Feb 5 at 15:49
it starts a process, that does not end, but sometimes fails, so that is why it need to be killed and restartd every hour.
– user1616685
Feb 5 at 16:05
it starts a process, that does not end, but sometimes fails, so that is why it need to be killed and restartd every hour.
– user1616685
Feb 5 at 16:05
I put exec bash in order to go on with the script
– user1616685
Feb 5 at 16:06
I put exec bash in order to go on with the script
– user1616685
Feb 5 at 16:06
1
1
But if
FirstAPP
doesn't end, how would anything else continue? Your command means "run FirstAPP
and when that finishes, run exec bash
". If that is not what you want, please edit and clarify what behavior you are expecting. You can also ping me in chat if you want and we can see if we can sort it out.– terdon♦
Feb 5 at 16:09
But if
FirstAPP
doesn't end, how would anything else continue? Your command means "run FirstAPP
and when that finishes, run exec bash
". If that is not what you want, please edit and clarify what behavior you are expecting. You can also ping me in chat if you want and we can see if we can sort it out.– terdon♦
Feb 5 at 16:09
1
1
Have you tried running the terminal in the background?
– wjandrea
Feb 5 at 16:24
Have you tried running the terminal in the background?
– wjandrea
Feb 5 at 16:24
|
show 2 more comments
1 Answer
1
active
oldest
votes
If you want your script to run a command and then continue executing, you need to tun the command in the background (&
, see https://unix.stackexchange.com/a/159514/22222). So, change your script to:
#!/bin/bash
xterm -e 'sh -c "$HOME/TEST/FirstAPP --test;"' &
## script opens the xterm and stops until I press CTRL+C
while true; do
....
That will launch the xterm
command in the background, keeping the terminal open and FirstAPP
running, and will then continue onto the other lines of your script.
The reason it worked with gnome-terminal
is because when you run gnome-terminal
, it apparently forks itself and returns control to the shell you launched it from. You can see this with strace
:
$ strace -e clone gnome-terminal
clone(child_stack=0x7fef6e44db30, flags=CLONE_VM|CLONE_FS|CLONE_FILES|CLONE_SIGHAND|CLONE_THREAD|CLONE_SYSVSEM|CLONE_SETTLS|CLONE_PARENT_SETTID|CLONE_CHILD_CLEARTID, parent_tidptr=0x7fef6e44e9d0, tls=0x7fef6e44e700, child_tidptr=0x7fef6e44e9d0) = 9534
clone(child_stack=0x7fef6dc4cb30, flags=CLONE_VM|CLONE_FS|CLONE_FILES|CLONE_SIGHAND|CLONE_THREAD|CLONE_SYSVSEM|CLONE_SETTLS|CLONE_PARENT_SETTID|CLONE_CHILD_CLEARTID, parent_tidptr=0x7fef6dc4d9d0, tls=0x7fef6dc4d700, child_tidptr=0x7fef6dc4d9d0) = 9535
# watch_fast: "/org/gnome/terminal/legacy/" (establishing: 0, active: 0)
clone(child_stack=0x7fef6d391b30, flags=CLONE_VM|CLONE_FS|CLONE_FILES|CLONE_SIGHAND|CLONE_THREAD|CLONE_SYSVSEM|CLONE_SETTLS|CLONE_PARENT_SETTID|CLONE_CHILD_CLEARTID, parent_tidptr=0x7fef6d3929d0, tls=0x7fef6d392700, child_tidptr=0x7fef6d3929d0) = 9540
# unwatch_fast: "/org/gnome/terminal/legacy/" (active: 0, establishing: 1)
# watch_established: "/org/gnome/terminal/legacy/" (establishing: 0)
+++ exited with 0 +++
Note the calls to clone
which, as explained in man clone
does:
clone() creates a new process, in a manner similar to fork(2).
So, unlike most programs, gnome-terminal
will make a clone of itself when launched. The normal way of launching something and then continuing with something else is to use &
to launch it in the background.
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "89"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1115846%2fxterm-in-bash-stops-script-from-executing%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
If you want your script to run a command and then continue executing, you need to tun the command in the background (&
, see https://unix.stackexchange.com/a/159514/22222). So, change your script to:
#!/bin/bash
xterm -e 'sh -c "$HOME/TEST/FirstAPP --test;"' &
## script opens the xterm and stops until I press CTRL+C
while true; do
....
That will launch the xterm
command in the background, keeping the terminal open and FirstAPP
running, and will then continue onto the other lines of your script.
The reason it worked with gnome-terminal
is because when you run gnome-terminal
, it apparently forks itself and returns control to the shell you launched it from. You can see this with strace
:
$ strace -e clone gnome-terminal
clone(child_stack=0x7fef6e44db30, flags=CLONE_VM|CLONE_FS|CLONE_FILES|CLONE_SIGHAND|CLONE_THREAD|CLONE_SYSVSEM|CLONE_SETTLS|CLONE_PARENT_SETTID|CLONE_CHILD_CLEARTID, parent_tidptr=0x7fef6e44e9d0, tls=0x7fef6e44e700, child_tidptr=0x7fef6e44e9d0) = 9534
clone(child_stack=0x7fef6dc4cb30, flags=CLONE_VM|CLONE_FS|CLONE_FILES|CLONE_SIGHAND|CLONE_THREAD|CLONE_SYSVSEM|CLONE_SETTLS|CLONE_PARENT_SETTID|CLONE_CHILD_CLEARTID, parent_tidptr=0x7fef6dc4d9d0, tls=0x7fef6dc4d700, child_tidptr=0x7fef6dc4d9d0) = 9535
# watch_fast: "/org/gnome/terminal/legacy/" (establishing: 0, active: 0)
clone(child_stack=0x7fef6d391b30, flags=CLONE_VM|CLONE_FS|CLONE_FILES|CLONE_SIGHAND|CLONE_THREAD|CLONE_SYSVSEM|CLONE_SETTLS|CLONE_PARENT_SETTID|CLONE_CHILD_CLEARTID, parent_tidptr=0x7fef6d3929d0, tls=0x7fef6d392700, child_tidptr=0x7fef6d3929d0) = 9540
# unwatch_fast: "/org/gnome/terminal/legacy/" (active: 0, establishing: 1)
# watch_established: "/org/gnome/terminal/legacy/" (establishing: 0)
+++ exited with 0 +++
Note the calls to clone
which, as explained in man clone
does:
clone() creates a new process, in a manner similar to fork(2).
So, unlike most programs, gnome-terminal
will make a clone of itself when launched. The normal way of launching something and then continuing with something else is to use &
to launch it in the background.
add a comment |
If you want your script to run a command and then continue executing, you need to tun the command in the background (&
, see https://unix.stackexchange.com/a/159514/22222). So, change your script to:
#!/bin/bash
xterm -e 'sh -c "$HOME/TEST/FirstAPP --test;"' &
## script opens the xterm and stops until I press CTRL+C
while true; do
....
That will launch the xterm
command in the background, keeping the terminal open and FirstAPP
running, and will then continue onto the other lines of your script.
The reason it worked with gnome-terminal
is because when you run gnome-terminal
, it apparently forks itself and returns control to the shell you launched it from. You can see this with strace
:
$ strace -e clone gnome-terminal
clone(child_stack=0x7fef6e44db30, flags=CLONE_VM|CLONE_FS|CLONE_FILES|CLONE_SIGHAND|CLONE_THREAD|CLONE_SYSVSEM|CLONE_SETTLS|CLONE_PARENT_SETTID|CLONE_CHILD_CLEARTID, parent_tidptr=0x7fef6e44e9d0, tls=0x7fef6e44e700, child_tidptr=0x7fef6e44e9d0) = 9534
clone(child_stack=0x7fef6dc4cb30, flags=CLONE_VM|CLONE_FS|CLONE_FILES|CLONE_SIGHAND|CLONE_THREAD|CLONE_SYSVSEM|CLONE_SETTLS|CLONE_PARENT_SETTID|CLONE_CHILD_CLEARTID, parent_tidptr=0x7fef6dc4d9d0, tls=0x7fef6dc4d700, child_tidptr=0x7fef6dc4d9d0) = 9535
# watch_fast: "/org/gnome/terminal/legacy/" (establishing: 0, active: 0)
clone(child_stack=0x7fef6d391b30, flags=CLONE_VM|CLONE_FS|CLONE_FILES|CLONE_SIGHAND|CLONE_THREAD|CLONE_SYSVSEM|CLONE_SETTLS|CLONE_PARENT_SETTID|CLONE_CHILD_CLEARTID, parent_tidptr=0x7fef6d3929d0, tls=0x7fef6d392700, child_tidptr=0x7fef6d3929d0) = 9540
# unwatch_fast: "/org/gnome/terminal/legacy/" (active: 0, establishing: 1)
# watch_established: "/org/gnome/terminal/legacy/" (establishing: 0)
+++ exited with 0 +++
Note the calls to clone
which, as explained in man clone
does:
clone() creates a new process, in a manner similar to fork(2).
So, unlike most programs, gnome-terminal
will make a clone of itself when launched. The normal way of launching something and then continuing with something else is to use &
to launch it in the background.
add a comment |
If you want your script to run a command and then continue executing, you need to tun the command in the background (&
, see https://unix.stackexchange.com/a/159514/22222). So, change your script to:
#!/bin/bash
xterm -e 'sh -c "$HOME/TEST/FirstAPP --test;"' &
## script opens the xterm and stops until I press CTRL+C
while true; do
....
That will launch the xterm
command in the background, keeping the terminal open and FirstAPP
running, and will then continue onto the other lines of your script.
The reason it worked with gnome-terminal
is because when you run gnome-terminal
, it apparently forks itself and returns control to the shell you launched it from. You can see this with strace
:
$ strace -e clone gnome-terminal
clone(child_stack=0x7fef6e44db30, flags=CLONE_VM|CLONE_FS|CLONE_FILES|CLONE_SIGHAND|CLONE_THREAD|CLONE_SYSVSEM|CLONE_SETTLS|CLONE_PARENT_SETTID|CLONE_CHILD_CLEARTID, parent_tidptr=0x7fef6e44e9d0, tls=0x7fef6e44e700, child_tidptr=0x7fef6e44e9d0) = 9534
clone(child_stack=0x7fef6dc4cb30, flags=CLONE_VM|CLONE_FS|CLONE_FILES|CLONE_SIGHAND|CLONE_THREAD|CLONE_SYSVSEM|CLONE_SETTLS|CLONE_PARENT_SETTID|CLONE_CHILD_CLEARTID, parent_tidptr=0x7fef6dc4d9d0, tls=0x7fef6dc4d700, child_tidptr=0x7fef6dc4d9d0) = 9535
# watch_fast: "/org/gnome/terminal/legacy/" (establishing: 0, active: 0)
clone(child_stack=0x7fef6d391b30, flags=CLONE_VM|CLONE_FS|CLONE_FILES|CLONE_SIGHAND|CLONE_THREAD|CLONE_SYSVSEM|CLONE_SETTLS|CLONE_PARENT_SETTID|CLONE_CHILD_CLEARTID, parent_tidptr=0x7fef6d3929d0, tls=0x7fef6d392700, child_tidptr=0x7fef6d3929d0) = 9540
# unwatch_fast: "/org/gnome/terminal/legacy/" (active: 0, establishing: 1)
# watch_established: "/org/gnome/terminal/legacy/" (establishing: 0)
+++ exited with 0 +++
Note the calls to clone
which, as explained in man clone
does:
clone() creates a new process, in a manner similar to fork(2).
So, unlike most programs, gnome-terminal
will make a clone of itself when launched. The normal way of launching something and then continuing with something else is to use &
to launch it in the background.
If you want your script to run a command and then continue executing, you need to tun the command in the background (&
, see https://unix.stackexchange.com/a/159514/22222). So, change your script to:
#!/bin/bash
xterm -e 'sh -c "$HOME/TEST/FirstAPP --test;"' &
## script opens the xterm and stops until I press CTRL+C
while true; do
....
That will launch the xterm
command in the background, keeping the terminal open and FirstAPP
running, and will then continue onto the other lines of your script.
The reason it worked with gnome-terminal
is because when you run gnome-terminal
, it apparently forks itself and returns control to the shell you launched it from. You can see this with strace
:
$ strace -e clone gnome-terminal
clone(child_stack=0x7fef6e44db30, flags=CLONE_VM|CLONE_FS|CLONE_FILES|CLONE_SIGHAND|CLONE_THREAD|CLONE_SYSVSEM|CLONE_SETTLS|CLONE_PARENT_SETTID|CLONE_CHILD_CLEARTID, parent_tidptr=0x7fef6e44e9d0, tls=0x7fef6e44e700, child_tidptr=0x7fef6e44e9d0) = 9534
clone(child_stack=0x7fef6dc4cb30, flags=CLONE_VM|CLONE_FS|CLONE_FILES|CLONE_SIGHAND|CLONE_THREAD|CLONE_SYSVSEM|CLONE_SETTLS|CLONE_PARENT_SETTID|CLONE_CHILD_CLEARTID, parent_tidptr=0x7fef6dc4d9d0, tls=0x7fef6dc4d700, child_tidptr=0x7fef6dc4d9d0) = 9535
# watch_fast: "/org/gnome/terminal/legacy/" (establishing: 0, active: 0)
clone(child_stack=0x7fef6d391b30, flags=CLONE_VM|CLONE_FS|CLONE_FILES|CLONE_SIGHAND|CLONE_THREAD|CLONE_SYSVSEM|CLONE_SETTLS|CLONE_PARENT_SETTID|CLONE_CHILD_CLEARTID, parent_tidptr=0x7fef6d3929d0, tls=0x7fef6d392700, child_tidptr=0x7fef6d3929d0) = 9540
# unwatch_fast: "/org/gnome/terminal/legacy/" (active: 0, establishing: 1)
# watch_established: "/org/gnome/terminal/legacy/" (establishing: 0)
+++ exited with 0 +++
Note the calls to clone
which, as explained in man clone
does:
clone() creates a new process, in a manner similar to fork(2).
So, unlike most programs, gnome-terminal
will make a clone of itself when launched. The normal way of launching something and then continuing with something else is to use &
to launch it in the background.
answered Feb 5 at 16:21
terdon♦terdon
66.6k12139221
66.6k12139221
add a comment |
add a comment |
Thanks for contributing an answer to Ask Ubuntu!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1115846%2fxterm-in-bash-stops-script-from-executing%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Where exactly does it stop? And what does FirstApp do? Does it ever exit? How is the terminal when it is "stopped"? Does it display a prompt? Why are you running
exec bash
?– terdon♦
Feb 5 at 15:49
it starts a process, that does not end, but sometimes fails, so that is why it need to be killed and restartd every hour.
– user1616685
Feb 5 at 16:05
I put exec bash in order to go on with the script
– user1616685
Feb 5 at 16:06
1
But if
FirstAPP
doesn't end, how would anything else continue? Your command means "runFirstAPP
and when that finishes, runexec bash
". If that is not what you want, please edit and clarify what behavior you are expecting. You can also ping me in chat if you want and we can see if we can sort it out.– terdon♦
Feb 5 at 16:09
1
Have you tried running the terminal in the background?
– wjandrea
Feb 5 at 16:24