NavigationUser loginSpam?See spam posts on this site? If so, please don't reply to the spam! Instead, just report the URL to the webmaster. |
[OT] Scripting question: the length limit of a list?Hi, I would like to write a bash script like the following one: for i in `some program that outputs a word list` where the word list can be very very long. I wonder what is the upper bound -- -- |
[OT] Scripting question: the length limit of a list?
On Thu, Nov 01, 2007 at 01:49:03PM -0700, Mike Bird wrote:
> On Thursday 01 November 2007 13:07, Wei Chen wrote:
> > I would like to write a bash script like the following one:
> >
> > for i in `some program that outputs a word list`
> > do
> > echo $i
> > done
> >
> > where the word list can be very very long. I wonder what is the upper bound
> > limit of the length of word lists in "for" loop of a bash script, or
> > does it only
> > depend on the hardware (say, RAM)? Thank you in advance.
>
> Assuming that the words are output one per line, something
> like the following can handle lists of any size:
>
> some program | while read i; do echo $i; done
A wild thought, but if you want to count the words in the output can you
not pipe it to wc? I haven't tried, this is just a thought...
--
richard
--
[OT] Scripting question: the length limit of a list?
On 11/01/07 15:07, Wei Chen wrote:
> Hi,
>
> I would like to write a bash script like the following one:
>
> for i in `some program that outputs a word list`
> do
> echo $i
> done
>
> where the word list can be very very long. I wonder what is the upper bound
> limit of the length of word lists in "for" loop of a bash script, or
> does it only
> depend on the hardware (say, RAM)? Thank you in advance.
I *think* that bash has a 128KB buffer limit.
--
Ron Johnson, Jr.
Jefferson LA USA
Give a man a fish, and he eats for a day.
Hit him with a fish, and he goes away for good!
--
[OT] Scripting question: the length limit of a list?
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Mike Bird wrote:
> On Thursday 01 November 2007 13:07, Wei Chen wrote:
>> I would like to write a bash script like the following one:
>>
>> for i in `some program that outputs a word list`
>> do
>> echo $i
>> done
>>
>> where the word list can be very very long. I wonder what is the upper bound
>> limit of the length of word lists in "for" loop of a bash script, or
>> does it only
>> depend on the hardware (say, RAM)? Thank you in advance.
>
> Assuming that the words are output one per line, something
> like the following can handle lists of any size:
>
> some program | while read i; do echo $i; done
>
Thanks for all the replies. I think the method of piping ``while read''
can be a good replacement. I have changed my script accordingly. Thank you.
- --
Cheers,
Wei Chen
http://www.acplex.com/people/wchen/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
iD8DBQFHKstXCIqXQV6BF28RAqvxAKCDrvpynyHIXjyf24/fUtemm93h5ACgxR9c
ROHPIpoaes/k767CXx/iWl4=
=ygd+
-----END PGP SIGNATURE-----
--