Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I am trying to write a command that will launch a few terminal tabs, execute something in each tab, and have each tab stay open after the command in finished, so I can look at the output and type more commands in each tab

something like this:

gnome-terminal --tab -e "ls -a" --tab -e "ls"

but the problem with this is that the tabs close as soon as the "ls" commands finish. Does anyone know how to make the tabs stay open?

share|improve this question

migrated from stackoverflow.com Aug 21 '10 at 5:36

This question came from our site for professional and enthusiast programmers.

add comment

2 Answers

up vote 7 down vote accepted

Gnome-terminal can either execute a command or open a shell, but not both.

There is a workaround to do both by encapsulating the command and subsequent invocation of the shell into one command.

$ gnome-terminal -e "bash -c \"echo foo; echo bar; exec bash\""

Read this answer to another, similar, question for more alternatives.

share|improve this answer
add comment

If you have xdotool and wmctrl installed, then the following shell script might work:

#!/usr/bin/env bash

window="$(xdotool search --class gnome-terminal | head -1)"
xdotool windowfocus $window
xdotool key ctrl+shift+t
xdotool type "$*"
xdotool key Return

I use it like this:

$ run-in-new-tab 'ls -l'

I found this idea on Trustin Lee's blog.

share|improve this answer
    
Thanks. This works pretty well. I have to add a sleep 1 after the ctrl+shift+t to get it to work for me though. I'll accept this if nothing else comes up soon –  Mark Aug 4 '10 at 5:07
    
Yeah - i found i had to have sleep 2 to make it work 100% of the time. Great solution though - i'm now opening 8 tabs, which ssh into various servers, start various processes etc, using this: my morning setup is now totally scripted :) –  Max Williams Feb 21 '13 at 10:00
add comment

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.