1
votes

Issue: Create a script that opens a terminal window with multiple tabs, each tab requires a different title to identify its purpose, in addition each tab should display a specific commmand (will not execute the command, the user will need to hit Enter to execute the command).

Example: The user needs to execute 3 commands: ifconfig, route -n and top, the user executes the script and it opens the terminal with 3 tabs, the first tab shows in the title Network and the prompt shows root$ ifconfig, the second tab shows in the title Routing and the prompt is like root$ route -n, the third tab shows the title Performance and the prompt shows root$ top. The commands are not running when the script is executed, the user needs to go into each tab and manually hit "Enter" to execute each command.

I am using the following script to open the terminal with multiple tabs, but am stuck trying to get the other features working, any assistance will be highly appreciated:

#bin/bash

tab="--tab"
cmd="bash -c 'pwd';bash"

foo=""

for i in 1 2 3; do

      foo+=($tab -e "$cmd")         
done

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

exit 0
1
That should be #!/bin/bash (note the exclamation mark).Tom Fenech
That should be #!/bin/sh and all bashisms for such an easy task better be avoided.Jens
@Jens, please demonstrate how to perform this task safely and reliably in /bni/sh.glenn jackman
Thanks for the responses, you're right it was a typo error (the exclamation mark).Mauricio Zamora
About the "bashisms", yea it's an easy task for 3 tabs, but in real life I need to open minimum 8 tabs and in each tab I need to type a different command with a large syntax, so I am looking for a way to automate the process. Any suggestion is welcome! :DMauricio Zamora

1 Answers

1
votes

You can save the state of your terminal using:

gnome-terminal --save-config=FILE

And call the load with:

gnome-terminal --load-config=FILE

Where FILE is the filename you would like to save.

So you can open 3 tabs and give them names etc, then save the config and in your script you can load it.

On the saved file you can edit properties like:

WorkingDirectory=
Title=

As for displaying a command and not running it, I don't have a solution.

You can check this: http://www.techrepublic.com/blog/linux-and-open-source/how-to-make-your-own-gnome-terminals/