Share your knowledge at the LQ Wiki.
Go Back > Forums > Linux Forums > Linux - General
User Name
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.


  Search this Thread
Old 06-08-2011, 03:42 PM   #1
LQ Newbie
Registered: Jun 2011
Distribution: debian lenny, arch
Posts: 15

Rep: Reputation: Disabled
termination of xtern launching an application with xterm -e

I hope I post to the right forum...

I wanted to launch sqlite3 with the command:

xterm -e sqlite3 /path/to/database "SELECT * FROM TABLE;" &

The xterm window flashes for a moment and then terminates.

Exactly the same result is encountered with:

a) xterm -e /bin/bash -l -c "sqlite3 /path/to/database "SELECT * FROM TABLE;"" (as suggested in man xterm)

b)giving an alias in .bashrc to:
sqlite3 /path/to/database "SELECT * FROM TABLE;"
and running: xterm -e alias

c)giving: xterm -e echo "something"

d)using: konsole -e sqlite3 /path/to/database "SELECT * FROM TABLE;" &

If a launch sqlite3 with:

xterm -e sqlite3 /path/to/database &

The xterm window launches with no problem and sqlite3 opens the database as expected. If I enter "SELECT * FROM TABLE;" every thing works as expected and I get the correct result.

The same applies if I launch xterm with: xterm &
and then:
sqlite3 /path/to/database "SELECT * FROM TABLE;"
to the command line.

I sometimes use xterm -e to launch applications to a separate window and never had the slightest problem.

I suspect it might be a bash thing (konsole and echo not working as well as above stated) and not an xterm thing. I made a search in man bash for quoting and backslashing but it didn't bright up things.

Anyone any ideas for solution or any other way to launch and get the SELECT result without any intervention?

Thank you for your time.

Last edited by zakotsi; 06-09-2011 at 01:08 AM.
Old 06-08-2011, 11:20 PM   #2
David the H.
Bash Guru
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1960Reputation: 1960Reputation: 1960Reputation: 1960Reputation: 1960Reputation: 1960Reputation: 1960Reputation: 1960Reputation: 1960Reputation: 1960Reputation: 1960
I've seen this issue discussed before. If I remember correctly, the -e option will execute the command, and the terminal will stay open for only as long as that command is active. If it's an interactive program like a text editor, it will stay open until you close that program. But something like echo simply prints and exits, and so the the terminal does also.

There is a -hold option, which will keep the window from being destroyed immediately, but the window is basically dead after that, with no more shell interaction possible. You have to kill the process in the launching shell or otherwise forcibly close the window. AFAIK, there's no way to use -e and still have an active shell after that command finishes running.

Edit: It looks like it's possible to do something like this:
xterm -e "( echo "foo" && bash )"
This will first run echo, and then a new bash shell inside the xterm. Of course this is because the commands are running inside a nested subshell of their own, so there's an extra layer involved, but that may be something you can live with.

Last edited by David the H.; 06-08-2011 at 11:30 PM. Reason: as stated
1 members found this post helpful.
Old 06-09-2011, 01:06 AM   #3
LQ Newbie
Registered: Jun 2011
Distribution: debian lenny, arch
Posts: 15

Original Poster
Rep: Reputation: Disabled
Thanks for prompt reply,

your example with echo "foo" worked but not sqlite /path/to/database/ "SELECT * from TABLE", but you set me on the right track as I only had to backslash the quotes and all was just fine!

The form that finally worked was:

xterm -e "( sqlite3 /path/to/database \"SELECT * FROM TABLE;\" && bash )"

The -hold option can also work just fine:

xterm -hold -e sqlite3 /path/to/database "SELECT * FROM TABLE;"

as (in this case) I only want a notification and not necessarily a running shell.


Last edited by zakotsi; 06-09-2011 at 01:18 AM.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
launching an installed application in hardy raphtor Linux - Newbie 8 04-12-2009 01:23 AM
Launching application + variables in FVWM Peff Linux - Software 2 06-28-2005 08:36 AM
launching a program from a C++ application Error1312 Programming 7 02-25-2004 08:18 AM
launching an application when X starts... DKnight Linux - Newbie 13 06-08-2003 07:43 AM
I get following output to xterm when launching xmms ... purpleburple Linux - General 11 07-26-2002 06:10 AM > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 07:48 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration