Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
[SOLVED] How to launch multiple xterms from bash script?
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Desktop Environments
View previous topic :: View next topic  
Author Message
dpaddy
Tux's lil' helper
Tux's lil' helper


Joined: 25 Jun 2008
Posts: 129

PostPosted: Mon Aug 24, 2020 9:12 pm    Post subject: [SOLVED] How to launch multiple xterms from bash script? Reply with quote

My goal is to have a bash script that launches multiple xterms where each xterm is running a program (of my choice, like "find ..." for example) and where each xterm has job control.

I don't get job control in an xterm if it is launched from within a bash script like so
Code:
/usr/bin/xterm -ls -sb -leftbar -font -*-fixed-medium-*-normal-*-15-*-100-100-*-*-*-* -geometry 102x27+0-0 -T "video" -e 'find -L . -name "video.~*~" -exec mplayer {} \;' &

The reason I have '&' in the line above is because when omitting it the bash script will not execute subsequent lines to launch additional xterms (I want a bash script to launch multiple xterms).

The code above does launch an xterm which is running the "find ..." command, but ^Z in that xterm will not suspend the command. Typing ^C in the xterm does kill the "find ..." command, but the xterm also dies and I don't want the xterm to terminate.

Is there a way to accomplish my goal via a bash script? :oops:


Last edited by dpaddy on Tue Aug 25, 2020 12:44 am; edited 1 time in total
Back to top
View user's profile Send private message
mike155
Advocate
Advocate


Joined: 17 Sep 2010
Posts: 2432
Location: Frankfurt, Germany

PostPosted: Mon Aug 24, 2020 11:39 pm    Post subject: Reply with quote

Let's use 'strace' to find out what happens. I use 'top' instead of your command, because it's easier to test.
Code:
term -e "top"             --> starts top directly. No bash involved, no job control
xterm                     --> starts bash in interactive mode. You have job control
xterm -e "bash"           --> starts bash in interactive mode. You have job control
xterm -e "bash -c top"    --> starts bash in non-interactive mode. No job control

The last command is the one that could help. But unfortunately, option '-c' forces bash to run in non-intercative mode, which disables job control.

So no, I don't see a way to start bash inside the xterm window in interactive mode AND to specify a command that bash should run.
Back to top
View user's profile Send private message
dpaddy
Tux's lil' helper
Tux's lil' helper


Joined: 25 Jun 2008
Posts: 129

PostPosted: Tue Aug 25, 2020 12:43 am    Post subject: Reply with quote

After much time searching, nothing I found worked and I had begun to suspect nothing could...

I'll take a different approach and achieve desired functionality using xdotool. In case someone happens by this and is inspired to play with xdotool but gets frustrated when attempting to drag windows around in fluxbox, I'll mention that in my experience some things require a mix of xdotool and cnee, and other things are impossible unless mucking around with fluxbox configuration files is added to the mix. :roll:
Back to top
View user's profile Send private message
Hu
Moderator
Moderator


Joined: 06 Mar 2007
Posts: 16016

PostPosted: Tue Aug 25, 2020 2:02 am    Post subject: Re: [SOLVED] How to launch multiple xterms from bash script? Reply with quote

This feels like another case of X-Y problem. Why do you want to have all of: (1) a new xterm, (2) a custom command as the initial command in the xterm, (3) job control, presumably to drop you back to a bash in that xterm? Getting any 2 of 3 is fairly easy. Getting all 3 requires some clever tricks.
dpaddy wrote:
The code above does launch an xterm which is running the "find ..." command, but ^Z in that xterm will not suspend the command. Typing ^C in the xterm does kill the "find ..." command, but the xterm also dies and I don't want the xterm to terminate.
xterm terminated because the contained process terminated. This is normal. Were you expecting xterm to also run a shell?
mike155 wrote:
The last command is the one that could help. But unfortunately, option '-c' forces bash to run in non-intercative mode, which disables job control.
Passing -i can force bash back into interactive mode, enabling use of ^Z. However, when the job is suspended, the xterm terminates and the whole setup is lost.
Back to top
View user's profile Send private message
dpaddy
Tux's lil' helper
Tux's lil' helper


Joined: 25 Jun 2008
Posts: 129

PostPosted: Tue Aug 25, 2020 4:33 am    Post subject: Reply with quote

Quote:
Why do you want to have all of: (1) a new xterm, (2) a custom command as the initial command in the xterm, (3) job control, presumably to drop you back to a bash in that xterm?

Yes, I do want it all (and so I shall have it, via xdotool). As to "Why...", well, because it is tasty. :wink:
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Desktop Environments All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum