niXforums Forum Index
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   PreferencesPreferences   Log in to check your private messagesLog in to check your private messages   Log inLog in 
·  nixdoc.net ·  man pages ·  Linux HOWTOs ·  FreeBSD Tips ·  Forums
navigation Forum index » Programming » shell
Quoting, variables, and xterm
Post new topic   Reply to topic Page 1 of 1 [3 Posts] View previous topic :: View next topic
Author Message
graftonfot@yahoo.com
*nix forums beginner


Joined: 23 Mar 2006
Posts: 3

PostPosted: Thu Jul 20, 2006 2:26 pm    Post subject: Quoting, variables, and xterm Reply with quote

Hello,

I believe I understand quoting and variables at least to a basic
degree, but I wonder if anyone could help me with the following.

We have a bash script which contains a function which uses its
arguments to launch any specified command in a new xterm. It looks
similar to:

function xterm_start {
prog=$1
title=$2
xterm -title $title -e $prog &

}

(there are other arguments for geometry and size, but I've left those
out for simplicity.)

Usually this function is passed the name of an executable shell script.


What I would like to be able to do is to pipe the stdout (and stderr)
of whatever command is passed in (as $1) through a tee, but I cannot
seem to find the right syntax to pass as xterm's -e parameter.

Quote:
From what I could find, using a new shell is the right approach here,
as in


xterm -e 'sh -c myprog 2>&1 | tee myprog.out'

....but I can't seem to be able to build a string like this using the
variable value(s). The closest I've seem to come was to use code that
looked like:

cmd="'sh -c $prog 2>&1 | tee $prog.out'"

(those are single quotes nested inside double quotes)

Using this code, with "myprog" as the value of $prog, an echo $cmd
yielded:

'sh -c myprog 2>&1 | tee myprog.out'

which looks right, but then xterm -e $cmd failed (as does xterm -e
"$cmd" and xterm -e '$cmd')

Is this possible, if so, what would be a good approach?

Thanks.
Back to top
Bill Marcum
*nix forums Guru


Joined: 28 Mar 2005
Posts: 1264

PostPosted: Thu Jul 20, 2006 5:52 pm    Post subject: Re: Quoting, variables, and xterm Reply with quote

On 20 Jul 2006 07:26:59 -0700, graftonfot@yahoo.com
<graftonfot@yahoo.com> wrote:
Quote:

Using this code, with "myprog" as the value of $prog, an echo $cmd
yielded:

'sh -c myprog 2>&1 | tee myprog.out'

which looks right, but then xterm -e $cmd failed (as does xterm -e
"$cmd" and xterm -e '$cmd')

eval xterm -e $cmd (or "$cmd"?)




--
All life evolves by the differential survival of replicating entities.
-- Dawkins
Back to top
Chris F.A. Johnson
*nix forums Guru


Joined: 20 Feb 2005
Posts: 2268

PostPosted: Thu Jul 20, 2006 7:22 pm    Post subject: Re: Quoting, variables, and xterm Reply with quote

On 2006-07-20, graftonfot@yahoo.com wrote:
Quote:
Hello,

I believe I understand quoting and variables at least to a basic
degree, but I wonder if anyone could help me with the following.

We have a bash script which contains a function which uses its
arguments to launch any specified command in a new xterm. It looks
similar to:

function xterm_start {
prog=$1
title=$2
xterm -title $title -e $prog &

}

(there are other arguments for geometry and size, but I've left those
out for simplicity.)

Usually this function is passed the name of an executable shell script.


What I would like to be able to do is to pipe the stdout (and stderr)
of whatever command is passed in (as $1) through a tee, but I cannot
seem to find the right syntax to pass as xterm's -e parameter.

From what I could find, using a new shell is the right approach here,
as in

xterm -e 'sh -c myprog 2>&1 | tee myprog.out'

...but I can't seem to be able to build a string like this using the
variable value(s). The closest I've seem to come was to use code that
looked like:

cmd="'sh -c $prog 2>&1 | tee $prog.out'"

cmd="$prog 2>&1 | tee \"$prog.out\""

Quote:
(those are single quotes nested inside double quotes)

Get rid of them.

Quote:
Using this code, with "myprog" as the value of $prog, an echo $cmd
yielded:

'sh -c myprog 2>&1 | tee myprog.out'

which looks right, but then xterm -e $cmd failed (as does xterm -e
"$cmd" and xterm -e '$cmd')

xterm -e "$cmd"

--
Chris F.A. Johnson, author <http://cfaj.freeshell.org>
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
===== My code in this post, if any, assumes the POSIX locale
===== and is released under the GNU General Public Licence
Back to top
Google

Back to top
Display posts from previous:   
Post new topic   Reply to topic Page 1 of 1 [3 Posts] View previous topic :: View next topic
The time now is Mon Dec 01, 2008 9:15 pm | All times are GMT
navigation Forum index » Programming » shell
Jump to:  

Similar Topics
Topic Author Forum Replies Last Post
No new posts Question on comparing to variables containing integers huub Perl 14 Thu Jul 20, 2006 11:02 am
No new posts Interpret variables in strings in ksh greenhakan@gmail.com shell 2 Wed Jul 19, 2006 2:03 pm
No new posts Retrieve ext. variables in python program alfa1234 python 7 Wed Jul 19, 2006 7:59 am
No new posts How to add variables to strings? yusufm Perl 6 Tue Jul 18, 2006 7:02 pm
No new posts How to add variables to strings? yusufm Perl 1 Tue Jul 18, 2006 7:01 pm

Houses for Sale | Remortgages | Loans | Mobile Phone | Free phpBB forum
Copyright © 2004-2005 DeniX Solutions SRL
 
Other DeniX Solutions sites: Unix/Linux blog |  electronics forum |  medicine forum |  science forum | 
Privacy Policy


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.4289s ][ Queries: 16 (0.3152s) ][ GZIP on - Debug on ]