13

How to write Bash script to open a terminal with two tabs, and execute commands in both tabs?

for instance:
tab 1 opens skype
tab 2 opens chromium-browser

In the end, I want one more thing: write a bash script with my skype username and password and feed those to skype.

Thanks

  • Do you want a script which opens two terminals for you? Or should the script open skype and chromium? (I will edit your question later to make it understandable). – rosch Oct 20 '12 at 11:38
  • Done , i edited it – Ahmed Zain El Dein Oct 20 '12 at 12:03
  • Sorry, I still don't get it, especially the last part. Please try to explain why you need the terminals. Bash does not need terminals to execute the commands. – rosch Oct 20 '12 at 12:19
  • I never heard the word "taped" in conjunction with "terminal" -- can you explain what a "taped terminal" is? Terminal in most cases refers to a terminal emulator or virtual console. – Tom Regner Oct 20 '12 at 12:37

2 Answers2

11

one terminal with two tabs:

gnome-terminal --tab --tab

use the -e switch to execute commands (or scripts):

gnome-terminal --tab -e "command1" --tab -e "command2"

(I don't think there is an easy way of feeding your credentials to skype via the terminal.)
Update: check w4YGcbTeIH's answer, skype allows giving credentials via the command line.

But beware, your credentials would be exposed and this should be avoided.

A script to open skype and chromium-browser would look like the following:

#!/bin/bash

skype --dbpath=<path> &
chromium-browser &

Put this code into myscript.sh and execute chmod +x myscript.sh (in a terminal) to make it executable.

About skype:

  • you can run skype without arguments (skype &) and it will load your default user profile ~/.Skype.
  • run it with --dbpath=<path> where <path> is your actual path of the Skype profile you want skype to load.

To run the script do one of the following:

  • open a terminal and execute ./myscript.sh
  • double click on the script and choose Run in the dialog.
rosch
  • 7,828
  • Once you have the bash script it will be executed by /bin/bash, there is no terminal in the game. What do you mean taped? I have never heard that word. – rosch Oct 20 '12 at 12:13
  • I edited my answer. gnome-terminal& is the command to open a terminal on a gnome desktop. – rosch Oct 20 '12 at 12:22
  • gnome-terminal --tab --tab is the command two have to tabs. Is this what you are looking for? – rosch Oct 20 '12 at 12:35
  • I think all is in my answer now, use the -e to execute commands. As for skype, I don't think it is possible what you are asking. I suggest you play around and get more familiar with bash by reading tutorials. Also make use of the man command. – rosch Oct 20 '12 at 12:55
  • Could you add a way to keep the terminal open after the script is run? – jcollum Mar 24 '13 at 02:09
  • @jcollum : there might be a way but I don't know it. – rosch Aug 27 '13 at 22:23
  • @rosch: How could i launch the tab in the same terminal window? --tab arg will launch terminal in a new window. – Darshan L Feb 07 '19 at 09:18
  • 1
    We may need a new answer soon: # Option “-e” is deprecated and might be removed in a later version of gnome-terminal.# – kmarsh Aug 19 '19 at 13:26
1
$ skype -h
Skype 4.0.0.8

Usage: skype [options]
Options:
  --dbpath=<path>       Specify an alternative path to store Skype data files.
                        Default: ~/.Skype
  --resources=<path>    Specify a path where Skype can find its resource files.
                        Default: /usr/share/skype
  --disable-api         Disable Skype Public API.
  --callto <nick>
  skype:<nick>?<action>
                        These commands allow Skype links handling.
  --pipelogin           Command line login. "echo username password | skype --pipelogin"
  --version             Display version information and exit.

echo username password | skype --pipelogin does what you want, but as rosch said : "Also, your credentials would be exposed and this should be avoided." They would be exposed on the history of the shell :

$ echo user pass | skype --pipelogin
[...]
$ history
[...]
 2006  echo user pass | skype --pipelogin
 2007  history
$