help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

when output of <( ... ) is stored in function argument, it can be used o


From: Ante Bilandzic
Subject: when output of <( ... ) is stored in function argument, it can be used only once - why?
Date: Tue, 24 Jan 2023 09:23:37 +0100

Hello,

Please can somebody answer the question in the subject line, or point me to
relevant documentation where the underlying mechanism at work is explained?

It is reduced to the bare bones with the following one-liner:

$ what(){ wc -l $1; wc -l $1; }; what <(ls)
18 /dev/fd/63
0 /dev/fd/63

In my particular case, 18 is the correct number of lines in the output of
<(ls). Why the 2nd and identical execution of 'wc -l' doesn't also get it
right?

Use case: I am supplying to function through the first argument list of
files generated via <(find ...), and then want to concatenate that list to
the already existing list of files in some physical file with 'cat', but
only if the output of <(find ...) is not empty. Therefore, I use 'wc' and
'cat' in the function body one after another on $1. Counterintuitively,
'wc' tells that $1 is not an empty file, while in the very next line 'cat'
sees $1 as an empty file.

Thanks!

Cheers,
Ante


reply via email to

[Prev in Thread] Current Thread [Next in Thread]