Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

bash - Shell script opening multiple terminals and executing distinct commands [closed]

I've tried to write my own shell script. So far I've managed to open 4 xterminals that can only execute ONE command because of the 'hold' option.

If i don't use this option, the terminals just disappear.

Here is my code :

#!/bin/sh
xterm -title "App 1" -hold -e mycommand | mysecondcommand  &
xterm -title "App 2" -hold -e mycommand | mysecondcommand  &
xterm -title "App 3" -hold -e mycommand | mysecondcommand  &
xterm -title "App 4" -hold -e mycommand | mysecondcommand

Not so sure if I'm supposed to execute the second command in the same terminal that way.

Any ideas ?

Thank you

like image 925
itachi42 Avatar asked Mar 26 '14 09:03

itachi42


People also ask

How do I open multiple terminals and run commands?

Running commands in different tabs is helpful, but sometimes two different processes are closely related and we want to see them together. For this, we can split our terminal window by right-clicking on it and selecting one of the options so that we can run two in the same window.

How do I run multiple commands in one shell script?

On Linux, there are three ways to run multiple commands in a terminal: The Semicolon (;) operator. The Logical OR (||) operator. The Logical AND (&&) operator.

What does $@ do Bash?

bash [filename] runs the commands saved in a file. $@ refers to all of a shell script's command-line arguments. $1 , $2 , etc., refer to the first command-line argument, the second command-line argument, etc. Place variables in quotes if the values might have spaces in them.

What is $@ and $* in shell script?

• $* - It stores complete set of positional parameter in a single string. • $@ - Quoted string treated as separate arguments. • $? - exit status of command.


1 Answers

Without -hold, the xterm will close as soon as the command is completed. You can execute multiple commands by using double quotes and command separators (eg ;, &):

xterm -title "App 1" -e "mycommand; mysecondcommand" 
like image 79
Josh Jolly Avatar answered Sep 25 '22 13:09

Josh Jolly