Skip to content
Advertisement

Run different bash scripts, started by one bash startscript, in different terminal tabs

I like to run more than one bash script, each in own terminal tab.

Now what did i found:

  • The follow run two scripts inside one terminal:

start.sh

#!/bin/bash
./task_1.sh &
./task_2.sh
sleep 5
exit

task_1.sh

#!/bin/bash
while true; do
    echo "task_1.sh"
    sleep 2
done

task_2.sh

#!/bin/bash
while true; do
    echo "task_1.sh"
    sleep 2
done

The follow are able to open a new tab on terminal:

xdotool key ctrl+shift+t

Now i have found the follow solution:

#!/bin/bash 
gnome-terminal 
--tab --title="task_1.sh" -e "./task_1.sh" 
--tab --title="task_2.sh" -e "./task_2.sh"

Thats working fine, a give a error message like, “replace the old “-e” by “–“. If I replace the “-e” by “–“, I getting after than only one tab. Dont get the 2`nd tab.

Advertisement

Answer

Run different bash scripts, started by one bash startscript, in different terminal tabs can be on some ways like:

gnome-terminal --tab --title="task_1.sh" -e "bash -c "./task_1.sh
  exec bash"" --tab --title="task_2.sh" -e "bash -c "./task_2.sh
  exec bash"" --tab --title="task_2.sh" -e "bash -c "./task_2.sh
  exec bash"" --tab --title="task_2.sh" -e "bash -c "./task_2.sh
""

gnome-terminal --tab --title="task_1.sh" -e "bash -c "sleep 5; ./task_1.sh
  exec bash"" --tab --title="task_2.sh" -e "bash -c "sleep 5; ./task_2.sh
  exec bash"" --tab --title="task_2.sh" -e "bash -c "sleep 5; ./task_2.sh
  exec bash"" --tab --title="task_2.sh" -e "bash -c "sleep 5; ./task_2.sh
""

gnome-terminal "" --tab --title="task_1.sh" -x "bash -c "sleep 5; ./task_1.sh
     exec bash"" --tab --title="task_2.sh" -x "bash -c "sleep 5; ./task_2.sh
     exec bash"" --tab --title="task_3.sh" -x "bash -c "sleep 5; ./task_3.sh
     exec bash"" --tab --title="task_4.sh" -x "bash -c "sleep 5; ./task_4.sh
""

gnome-terminal 
    --tab --title="task_1.sh" -e "./task_1.sh" 
    --tab --title="task_2.sh" -e "./task_2.sh" 
    --tab --title="task_3.sh" -e "./task_3.sh" 
    --tab --title="task_4.sh" -e "./task_4.sh"

gnome-terminal --tab --active -- bash -c "echo Hello Tab 1; exec bash"
gnome-terminal --tab --active -- bash -c "echo Hello Tab 2; exec bash"
gnome-terminal --tab --active -- bash -c "echo Hello Tab 3; exec bash"
gnome-terminal --tab --active -- bash -c "echo Hello Tab 4; exec bash"
gnome-terminal


gnome-terminal 
gnome-terminal --title="task_0.sh" -x ./test_0.sh
gnome-terminal --title="task_1.sh" -x ./test_1.sh
gnome-terminal --title="task_2.sh" -x ./test_2.sh
gnome-terminal --title="task_3.sh" -x ./test_3.sh


xdotool key "ctrl+shift+t"
xdotool key "ctrl+shift+t"
xdotool key "ctrl+shift+t"
xdotool key "ctrl+shift+t"
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement