Re: BASH question: executing a cmd with a pipe that is in a variable

2005-08-10 Thread Steven W. Orr
On Tuesday, Aug 9th 2005 at 15:13 -0400, quoth Larry Cook:

=I'm being stupid!  Can someone please help?
=
=I've got a BASH script with the following:
=
=CMD=zcat myfile | tar xf -
=$CMD
=
=This puts zcat's output to stdout, rather than piping it to tar like I want.
=Now I'm sure this is how it *should* work. :-(  Unfortunately, I can't figure
=out how to get it to work like I want.

You've already gotten the solution to use the eval command. But I thought 
it would be instructional to 'splain it so you know why.

Look at this example and it becomes more obvious.

foo='echo hello | cat'

if you say 

$foo 

you're expecting to see a hello. Instead you correctly see

hello | cat

i.e., what you're really getting is this

echo 'hello | cat'

which makes it perfectly obvious what's happening. If you really want the 
command to be executed you need an eval to prevent the myfile | tar xf -
to all not be args 1 through 5 to zcat.

Sounds logical to a Vulcan...

-- 
Time flies like the wind. Fruit flies like a banana. Stranger things have  .0.
happened but none stranger than this. Does your driver's license say Organ ..0
Donor?Black holes are where God divided by zero. Listen to me! We are all- 000
individuals! What if this weren't a hypothetical question?
steveo at syslang.net
___
gnhlug-discuss mailing list
gnhlug-discuss@mail.gnhlug.org
http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss


BASH question: executing a cmd with a pipe that is in a variable

2005-08-09 Thread Larry Cook

I'm being stupid!  Can someone please help?

I've got a BASH script with the following:

CMD=zcat myfile | tar xf -
$CMD

This puts zcat's output to stdout, rather than piping it to tar like I want. 
Now I'm sure this is how it *should* work. :-(  Unfortunately, I can't figure 
out how to get it to work like I want.


Thanks,
Larry
___
gnhlug-discuss mailing list
gnhlug-discuss@mail.gnhlug.org
http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss


Re: BASH question: executing a cmd with a pipe that is in a variable

2005-08-09 Thread Bruce Dawson

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Larry Cook wrote:

| I'm being stupid!  Can someone please help?
|
| I've got a BASH script with the following:
|
| CMD=zcat myfile | tar xf - $CMD

You want eval $CMD.

| This puts zcat's output to stdout, rather than piping it to tar
| like I want. Now I'm sure this is how it *should* work. :-(
| Unfortunately, I can't figure out how to get it to work like I
| want.
|
| Thanks, Larry ___
| gnhlug-discuss mailing list gnhlug-discuss@mail.gnhlug.org
| http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss


-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.1 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFC+QMb/TBScWXa5IgRAgzRAJ9PtQgS0fleT2oKzQJPGNPBCn7oMwCeMjnn
QSjEvIb2nvDUlMDVrCyYJmM=
=1VpX
-END PGP SIGNATURE-

___
gnhlug-discuss mailing list
gnhlug-discuss@mail.gnhlug.org
http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss


Re: BASH question: executing a cmd with a pipe that is in a variable

2005-08-09 Thread Larry Cook

Bruce,

Thanks for the quick response and simple solution.

Larry

Bruce Dawson wrote:

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Larry Cook wrote:

| I'm being stupid!  Can someone please help?
|
| I've got a BASH script with the following:
|
| CMD=zcat myfile | tar xf - $CMD

You want eval $CMD.

| This puts zcat's output to stdout, rather than piping it to tar
| like I want. Now I'm sure this is how it *should* work. :-(
| Unfortunately, I can't figure out how to get it to work like I
| want.
|
| Thanks, Larry ___
| gnhlug-discuss mailing list gnhlug-discuss@mail.gnhlug.org
| http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss


-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.1 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFC+QMb/TBScWXa5IgRAgzRAJ9PtQgS0fleT2oKzQJPGNPBCn7oMwCeMjnn
QSjEvIb2nvDUlMDVrCyYJmM=
=1VpX
-END PGP SIGNATURE-





___
gnhlug-discuss mailing list
gnhlug-discuss@mail.gnhlug.org
http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss


Re: BASH question: executing a cmd with a pipe that is in a variable

2005-08-09 Thread Kevin D. Clark

Larry Cook writes:

 I'm being stupid!  Can someone please help?

 I've got a BASH script with the following:

  CMD=zcat myfile | tar xf -
  $CMD

 This puts zcat's output to stdout, rather than piping it to tar like I
 want. 

This is because the shell's order of operations is different than what
you think it is.  The man pages describes this in gory detail.

 Now I'm sure this is how it *should* work. :-(  Unfortunately, I
 can't figure out how to get it to work like I want.

You could either just invoke zcat myfile | tar xf - directly (but I
guess you have some reason why you can't do that) or else you could
just try eval $CMD.

Hope this helps,

--kevin
-- 
GnuPG ID: B280F24E And the madness of the crowd
alumni.unh.edu!kdc Is an epileptic fit
   -- Tom Waits
___
gnhlug-discuss mailing list
gnhlug-discuss@mail.gnhlug.org
http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss


Re: bash question

2002-09-23 Thread Thomas M. Albright

On Mon, 23 Sep 2002 [EMAIL PROTECTED] wrote:

 
 In a message dated: Mon, 23 Sep 2002 11:37:40 EDT
 Thomas M. Albright said:
 
 If the due date is greater than today, it outputs the message Due in x
 days. If the due date is less than today I get a message saying You
 are -x days past due. How can I convert the negative number into a
 positive one in bash?
 
 Well, assuming that 'x' is a variable which contains some whole 
 number representing the number of days in which 'it' is due, a 
 negative number representing an over-due 'it', then:
 
   abs_x=`echo '$x' | sed s/-//`
 
 ought to do it.
 
Yay! Thanks!

-- 
TARogue (Linux user number 234357)
 You can always tell a Texan, but you can't tell him much. - Chris Wall

___
gnhlug-discuss mailing list
[EMAIL PROTECTED]
http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss



Re: bash question

2002-09-23 Thread Steven W. Orr

On Mon, 23 Sep 2002, Thomas M. Albright wrote:

=I don't have any of my bash scripting books handy so I figured I'd ask
=here: I have a script that checks due dates. I use `date +%j` to convert
=both today and the date due into day of year. (eg - today is 266) I then
=subtract today from the due date.
=
=If the due date is greater than today, it outputs the message Due in x
=days. If the due date is less than today I get a message saying You
=are -x days past due. How can I convert the negative number into a
=positive one in bash?
daysPastDue=$((daysPastDue * -1))

-- 
-Time flies like the wind. Fruit flies like a banana. Stranger things have -
-happened but none stranger than this. Does your driver's license say Organ
-Donor?Black holes are where God divided by zero. Listen to me! We are all-
-individuals! What if this weren't a hypothetical question? [EMAIL PROTECTED]

___
gnhlug-discuss mailing list
[EMAIL PROTECTED]
http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss