TPS
TPS

Reputation: 518

Script for running processes in foreground but on different terminal tab

I am new to shell scripting. I am using gnome-terminal. I have written one simple script which I need to start my process one-by-one, Here is my Script:

#!/bin/bash    
    cd A/
    sleep 1
    ./exe1 &
    echo "-------- exe1 STARTED------"

    cd ../../B/
    sleep 1
    ./exe2_a &
    sleep 1
    ./exe2_b &
    echo "--------exe2 STARTED------"

    cd ../C/
    sleep 1
    ./NAV_exe3_a &
    sleep 1 
    ./NAV_exe3_b &
    echo "--------exe3 STARTED------"

As you can see I am starting 5 different processes in the background, but how do I start them in 5 different tabs in terminal (in foreground) by a single script? Is there any way?

Upvotes: 1

Views: 1312

Answers (1)

larsks
larsks

Reputation: 311526

If you have gnome-terminal available, you can do something like this:

gnome-terminal \
  --tab -e "./exe1" \
  --tab -e "./exe2" \
  --tab -e "./exe3"

Note that this will start everything in parallel. You can implement timed delays using sleep, if you need that sort of thing:

gnome-terminal \
  --tab -e "./exe1" \
  --tab -e "sh -c 'sleep 5; ./exe2'" \
  --tab -e "sh -c 'sleep 10; ./exe3'"

Upvotes: 2

Related Questions