Re: [OT] writing filters in sh

2010-10-28 Thread Chip Camden
Quoth Chad Perrin on Wednesday, 27 October 2010: I know that in sh you can get the contents out of files specified as command line arguments: while read data; do echo $data done $@ I know you can also get the contents of files from pipes and redirects: while read

Re: [OT] writing filters in sh

2010-10-28 Thread Chad Perrin
On Thu, Oct 28, 2010 at 08:11:48AM -0700, Chip Camden wrote: Here's a way to do what you're wanting to do. Unfortunately, it isn't a generalized, single construct: #!/bin/sh if [ $# -ge 1 ];then exec cat $@ | $0 exit fi while read data; do echo $data done My lame attempts

Re: [OT] writing filters in sh

2010-10-28 Thread Chip Camden
Quoth Chad Perrin on Thursday, 28 October 2010: On Thu, Oct 28, 2010 at 08:11:48AM -0700, Chip Camden wrote: Here's a way to do what you're wanting to do. Unfortunately, it isn't a generalized, single construct: #!/bin/sh if [ $# -ge 1 ];then exec cat $@ | $0 exit fi

Re: [OT] writing filters in sh

2010-10-28 Thread Devin Teske
On Wed, 2010-10-27 at 15:28 -0600, Chad Perrin wrote: I know that in sh you can get the contents out of files specified as command line arguments: while read data; do echo $data done $@ I know you can also get the contents of files from pipes and redirects: while

Re: [OT] writing filters in sh

2010-10-28 Thread Polytropon
On Thu, 28 Oct 2010 09:17:12 -0700, Chip Camden sterl...@camdensoftware.com wrote: Perhaps someone with more sh fu can transform the 'if' paragraph into a one-liner at least. When I tried to do so, I got an unexpected ; error. Not tested, but this should do the trick: #!/bin/sh

Re: [OT] writing filters in sh

2010-10-28 Thread Polytropon
On Thu, 28 Oct 2010 19:28:26 +0200, Polytropon free...@edvax.de wrote: On Thu, 28 Oct 2010 09:17:12 -0700, Chip Camden sterl...@camdensoftware.com wrote: Perhaps someone with more sh fu can transform the 'if' paragraph into a one-liner at least. When I tried to do so, I got an unexpected

Re: [OT] writing filters in sh

2010-10-28 Thread Chip Camden
Quoth Polytropon on Thursday, 28 October 2010: On Thu, 28 Oct 2010 09:17:12 -0700, Chip Camden sterl...@camdensoftware.com wrote: Perhaps someone with more sh fu can transform the 'if' paragraph into a one-liner at least. When I tried to do so, I got an unexpected ; error. Not tested,

Re: [OT] writing filters in sh

2010-10-28 Thread Karl Vogel
On Thu, 28 Oct 2010 09:17:12 -0700, Chip Camden sterl...@camdensoftware.com said: C Perhaps someone with more sh fu can transform the 'if' paragraph into a C one-liner at least. When I tried to do so, I got an unexpected ; error. Try this: #!/bin/sh test $# -ge 1 cat $@ | exec

Re: [OT] writing filters in sh

2010-10-28 Thread Chip Camden
Quoth Karl Vogel on Thursday, 28 October 2010: On Thu, 28 Oct 2010 09:17:12 -0700, Chip Camden sterl...@camdensoftware.com said: C Perhaps someone with more sh fu can transform the 'if' paragraph into a C one-liner at least. When I tried to do so, I got an unexpected ; error. Try

Re: [OT] writing filters in sh

2010-10-28 Thread Devin Teske
On Thu, 2010-10-28 at 09:17 -0700, Chip Camden wrote: Quoth Chad Perrin on Thursday, 28 October 2010: On Thu, Oct 28, 2010 at 08:11:48AM -0700, Chip Camden wrote: Here's a way to do what you're wanting to do. Unfortunately, it isn't a generalized, single construct: #!/bin/sh

Re: [OT] writing filters in sh

2010-10-28 Thread John Levine
I was hoping for a generalized, simple idiom for this, rather than needing to implement it myself, for demonstration purposes #!/bin/sh cat $@ | while read x do echo I saw $x done Sheesh. R's, John

Re: [OT] writing filters in sh

2010-10-28 Thread Chip Camden
Quoth John Levine on Thursday, 28 October 2010: I was hoping for a generalized, simple idiom for this, rather than needing to implement it myself, for demonstration purposes #!/bin/sh cat $@ | while read x do echo I saw $x done

Re: [OT] writing filters in sh

2010-10-28 Thread Charlie Kester
On Thu 28 Oct 2010 at 13:52:27 PDT Chip Camden wrote: stage_directionSmacks forehead as if starring in a V-8 commercial/stage_direction A friend of mine used to call that a Neanderthal Moment. (Smack your forehead, shrug your shoulders, and imagine it is reshaping your body.)

[OT] writing filters in sh

2010-10-27 Thread Chad Perrin
I know that in sh you can get the contents out of files specified as command line arguments: while read data; do echo $data done $@ I know you can also get the contents of files from pipes and redirects: while read data; do echo $data done In Perl, you can use a

Re: [OT] writing filters in sh

2010-10-27 Thread Karl Vogel
On Wed, 27 Oct 2010 15:28:41 -0600, Chad Perrin per...@apotheon.com said: C In Perl, you can use a single construct to [read files or pipes], and it C can also take multiple filenames as arguments and effectively C concatenate their contents: C while () { print $_; } C Please let me know if