|
|
|
|
|
|
| Author |
Message |
graftonfot@yahoo.com *nix forums beginner
Joined: 23 Mar 2006
Posts: 3
|
Posted: Thu Jul 20, 2006 2:26 pm Post subject:
Quoting, variables, and xterm
|
|
|
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
|
Posted: Thu Jul 20, 2006 5:52 pm Post subject:
Re: Quoting, variables, and xterm
|
|
|
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
|
Posted: Thu Jul 20, 2006 7:22 pm Post subject:
Re: Quoting, variables, and xterm
|
|
|
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 |
|
 |
|
|
The time now is Mon Dec 01, 2008 9:15 pm | All times are GMT
|
|
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
|
|