How do I run the same linux command in more than one tab/shell simultaneously? How do I run the same linux command in more than one tab/shell simultaneously? shell shell

How do I run the same linux command in more than one tab/shell simultaneously?


Why not do something like

for i in {1..100}do    ./myprog argument1 argument2 &done

This is in case the shell is bash. You can look into other looping constructs in case of other shells.


Running the jobs asynchronously with redirected output is the simplest solution, but if you really want each process to run in its own terminal, a good option is to use a terminal emulator like screen or tmux. For example:

yes | sed 5q | while read k; do  # iterate 5 times  tmux new-session -d 'sh -c "/path/to/myprog arg1 arg2; sh"'&done

The trailing sh causes the session to remain alive after myprog terminates, and the intial yes pipeline is used instead of seq since it works where seq is not available (there are lots of ways to iterate!)

Once the sessions are running, you can attach to them individually to view the output. (See tmux documentation for details.)


if you are using gnome terminal, try this one

gnome-terminal --maximize --tab-with-profile=default -e '/bin/sh -c ./myprog argument1 argument2' --tab-with-profile=default -e '/bin/sh -c ./myprog argument1 argument2' --tab-with-profile=default -e '/bin/sh -c ./myprog argument1 argument2'

please check gnome-terminal man page for more options