Problem with replacing a process in a file command

It’s easier to show how to try to describe in words.

find . -name jo\* -print > list
cat list
#./jo1
#./jo2
#./jo3

# the "file" by reading the list of files from the file "list"
file -f list
#./jo1: ASCII text
#./jo2: ASCII text
#./jo3: ASCII text

#now with process substitution
file -f <(find . -name jo\* -print)

nothing displays ..; (

#repeat with -x
set -x
file -f <(find . -name jo\* -print)
set +x

#shows
+ file -f /dev/fd/63
++ find . -name 'jo*' -print
+ set +x

therefore should work. But does not. why?

EDIT

Please note: process substitution should work wherever you enter a file name, say:

diff <(some command) <(another command)

bash above is used as

diff /dev/fd/... /dev/fd/...

also, for example, in grep- you can use:

grep -f <(command_for_produce_the_patterns) files..

again, bashinternally uses this as

grep -f /dev/fd/63 files....

So the same should work infile

file -f <(command)
+4
source share
2 answers

. file, ( 5.22 Debian jessie). , -f , , . , ( ).

, strace:

$ strace file -f <(echo foo)
open("/proc/self/fd/13", O_RDONLY)      = 3
fstat(3, {st_mode=S_IFIFO|0600, st_size=0, ...}) = 0
read(3, "foo\n", 4096)                 = 5
read(3, "", 4096)                       = 0
lseek(3, 0, SEEK_SET)                   = -1 ESPIPE (Illegal seek)
read(3, "", 4096)                       = 0
close(3)                                = 0

3 . . , , , . , .

-f unwrap:

private int
unwrap(struct magic_set *ms, const char *fn)
{
    // …
    if (strcmp("-", fn) == 0) {
            f = stdin;
            wid = 1;
    } else {
        if ((f = fopen(fn, "r")) == NULL) {
                (void)fprintf(stderr, "%s: Cannot open `%s' (%s).\n",
                    progname, fn, strerror(errno));
                return 1;
        }
        while ((len = getline(&line, &llen, f)) > 0) {
            // … code to determine column widths
        }
        rewind(f);
    }
    // Code to read the file names from f follows
}

- ( ), , . rewind . - .

+5

< (cmd) $(cmd).

-1

Source: https://habr.com/ru/post/1674414/


All Articles