It's a bug in the libmagic library that file
is using.
A simple workaround is a "useless use of cat":
echo '#! /bin/sh' | file -
cat /path/to/fifo-or-special | file -
The bug was first introduced in https://github.com/file/file/commit/fb6084e0f08:
commit fb6084e0f08aef8991afcb3eb74168a456601908
Author: Christos Zoulas <christos@zoulas.com>
Date: Tue May 28 21:24:31 2013 +0000
don't print a space if there was an error. (from Jan Kaluza)
It was then fixed, but only for block and character devices, NOT for FIFOs in https://github.com/file/file/commit/a9124dcb4e. An incomplete fix for <(...)
on Linux was in https://github.com/file/file/commit/adbe541c32.
The fix for devices could be replicated for FIFOs. See the patch at the end of the answer (apply by hand because this site mangles tabs and keep in mind that it's against a MIRROR ONLY repo).
But that still leaves:
mkfifo fifo; file -s fifo
fifo: writable, no read permission
Stupid and wrong, because the FIFO has read permission.
Repairing this will mean either rewriting half of libmagic, or add yet another couple of ifdef spaghetti and special cases to the horrible mess.
diff --git a/src/fsmagic.c b/src/fsmagic.c
index 5204f20d..20b7f438 100644
--- a/src/fsmagic.c
+++ b/src/fsmagic.c
@@ -270,8 +270,10 @@ file_fsmagic(struct magic_set *ms, const char *fn, struct stat *sb)
/* TODO add code to handle V7 MUX and Blit MUX files */
#ifdef S_IFIFO
case S_IFIFO:
- if((ms->flags & MAGIC_DEVICES) != 0)
+ if((ms->flags & MAGIC_DEVICES) != 0) {
+ return 0;
break;
+ }
if (mime) {
if (handle_mime(ms, mime, "fifo") == -1)
return -1;
file -s - < <(echo \#include \<stdio.h\>)
(and is that an acceptable solution for your use case)? – steeldriver Mar 13 '20 at 01:00