Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I want one script to open several Tabs in different folders.

While searching I found this entry, but an exchange like seen below did open a Terminal with three tabs in my home folder. The error message showed:

Failed to parse arguments: Unknown option --execute=cd /some/thing/

The script looks like this:

#!/bin/sh
gnome-terminal --tab --execute="cd /some/thing/" \
          --tab --execute="cd /home/" \
          --tab --execute="cd /home/" \
exit 0

A Variation with --working-directory="/some/thing/" did also not help. Can you see a mistake?

share|improve this question

2 Answers 2

up vote 3 down vote accepted

The following works for me on oneiric. You can use this in place of your version:

#!/bin/bash
gnome-terminal --tab  --working-directory="/var/www/" --tab --working-directory='/home/' --tab --working-directory='/home/'
exit 0
share|improve this answer

Your specific error is caused by not using the --execute option properly. If you look at the excerpt from the man page below, you'll note that --execute does not have an equals sign listed as part of the syntax, as it simply executes the entire rest of the command line. An example of correct use would be:

gnome-terminal --execute play '/home/cjohnson/Still Alive.mp3'

IMPORTANT NOTE:
Using cd is a bit of a special case, anyway. cd is not like most commands—it does not launch a binary/executable of its own. It is interpreted directly by bash (or whatever shell you are using). Therefore attempting to invoke cd doesn't agree with the --execute and -x flags (which seem to want to directly spawn a child process). The same issue will occur (I've checked) with other commands which are directly processed by bash like home. Even if used properly, without the equals sign, it will still result in an error: "File or directory not found." Therefore using the --working-directory=[DIRECTORY] option is your best bet for doing what you want to do.

ANOTHER IMPORTANT NOTE:
Even if this weren't the case, you would still run into trouble. The problem lies in trying to use the --execute option when you actually intend the meaning of the --command option. In the man page documentation, it states specifically

-e, --command=STRING
Execute the argument to this option inside the terminal.

-x, --execute
Execute the remainder of the command line inside the terminal.

(emphasis mine)

In other words, it's probably not going to parse it in the way you think it should. Using --execute prevents you from passing any further options to gnome-terminal.

An excerpt from one of my own scripts where I run multiple commands in separate tabs (names changed for my privacy/security):

gnome-terminal --tab --command="ssh cjohnson@GLaDOS" --tab --command="ssh drattman@GLaDOS"

(Incidentally, trying to use the --command flag with cd or home will also result in the familiar "No such file or directory" error.)

I hope this isn't too long. I'm just trying to be thorough.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.