Search code examples
bashubuntugnome-terminal

Ubuntu shell script to open multiple tabs , load bashrc file


hi i am doing following steps manually

  1. open terminal (loads ~/.bashrc)
  2. open 6 tabs
  3. set titles for each tab
  4. source libray files source test.sh tab1 command with different parameter in each tab.
  5. run Test (./run.sh)

i tried to automate the above steps uing shell script using gnome-terminal (using following link) , https://askubuntu.com/questions/500357/opening-multiple-terminal-tabs-and-running-command the tabs are opening but titles are not saving it is resetting and the command source ~/test.sh tab1 giving error "No such file or directory"

Code:

#!/bin/bash

cd /media/Extra/Project

tab=" --tab-with-profile=Default"
options=(--tab --title=Terminal)

cmds[1]="'source ~/test_1.sh; ./run.sh'"
titles[1]="test_1"

cmds[2]="'source ~/test_2.sh; ./run.sh'"
titles[2]="test_2"


cmds[3]="'source ~/test_3.sh; ./run.sh'"
titles[3]="test_3"

cmds[4]="'source ~/test_4.sh; ./run.sh'"
titles[4]="test_4"

cmds[5]="'source ~/test_5.sh; ./run.sh'"
titles[5]="test_5"

cmds[6]="'source ~/test_6.sh; ./run.sh'"
titles[6]="test_6"

for i in 1 2 3 4 5 6; do
    options+=($tab --title="${titles[i]}"  -e "bash -ic \"${cmds[i]} ; bash\"" )     
done

gnome-terminal "${options[@]}"

exit 0

Solution

  • The single quotes inside the double quotes are causing the entire string to be interpreted as the name of a command, whitespace and all, which of course does not work. Remove them and your script should work (albeit still somewhat awkwardly).

    See also http://mywiki.wooledge.org/BashFAQ/050