On Mon, Oct 18, 2004 at 11:13:21PM +0200, Shlomo Solomon wrote:
> First of all, thanks to both Oren and Yosef. Both solutions worked.
> 
> But, now I'm confused. Isn't the whole point of redirection that you can use a 
> file to get input or accept output even if the program was originally desiged 
> to work only from the command line?

No, not at all. For programs getting input only from the command line
there are exectly the tools mentioned (xargs and backquotes).
Redirection is for making programs normally reading input from the
"standard input", e.g. from a terminal emulator window, read it from a
file (and piping is for making them read the output of another program).

Note, BTW, that there is a big difference - the command line for a
process is completely built before it starts running. It's also much
more limited (by default up to ~128K bytes in Linux). Redirection, OTOH,
happens at runtime - with piping you can have unlimited data moving,
not predetermined. E.g.

% dd if=/dev/zero bs=1G count=10 | wc -c
10737418240
10+0 records in
10+0 records out
10737418240 bytes transferred in 19.786694 seconds (542658530 bytes/sec)

That's 10GB moving from the kernel to wc to count. OTOH, the maximum for
'n' in the following command is 130189 (at least in my machine. Anyone
knows why exactly this number? Maybe the size of the command line plus
the environment (also passed to the process) is 128K? Much closer here,
but not exactly):

% n=130189; /bin/echo `dd if=/dev/zero bs=1 count=$n | tr '\000' 'a'` | wc -c
130189+0 records in
130189+0 records out
130189 bytes transferred in 0.517898 seconds (251380 bytes/sec)
130190
% n=130190; /bin/echo `dd if=/dev/zero bs=1 count=$n | tr '\000' 'a'` | wc -c
130190+0 records in
130190+0 records out
130190 bytes transferred in 0.397579 seconds (327457 bytes/sec)
bash: /bin/echo: Argument list too long
0

Note BTW that 'echo' (not /bin/echo) is your shell's builtin, not a
real process, and won't suffer from this limitation.

> I don't see why the pipe or redirection I 
> was using didn't do the job.

I suggest you google for (a subset of) 'backquote xargs redirection
piping' (I just tried and there are 165 results, but some of them
seem to be ads. Some are probably good, though).
I did not fully read it but I guess the
"BASH Programming - Introduction HOW-TO" (or even the
"Advanced Bash-Scripting Guide", if you are brave) might be quite good.

Good luck,
-- 
Didi


=================================================================
To unsubscribe, send mail to [EMAIL PROTECTED] with
the word "unsubscribe" in the message body, e.g., run the command
echo unsubscribe | mail [EMAIL PROTECTED]

Reply via email to