1

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?

tux3
  • 7,171
  • 6
  • 39
  • 51
TPS
  • 493
  • 1
  • 5
  • 28
  • It depends on what terminal emulator you are using. The shell doesn't know anything about your terminals; it only knows about the environment provided to it by its parent process. – chepner Mar 18 '13 at 15:31
  • [Script new tab Mac Terminal](http://stackoverflow.com/questions/7171725/open-new-terminal-tab-from-command-line-mac-os-x) – ma11hew28 Nov 09 '13 at 18:58

1 Answers1

2

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'"
larsks
  • 277,717
  • 41
  • 399
  • 399
  • Thank You! it works great for me. but `--tab -e "sleep 10; ./exe3"` is not that perfect. Do you have any other solution for this? – TPS Mar 18 '13 at 15:37
  • You didn't indicate in what manner it wasn't working, but check out my update; I think this will solve your problem. – larsks Mar 18 '13 at 19:24
  • Thanks Larsks once again, But `sh -c` also did not work. But my task of running all my processes in foreground working nice, but in different terminals (not tabs) thank You once again! – TPS Mar 19 '13 at 16:22