If I do this:
echo <(cat)
I get:
/dev/fd/63
so say at the command line I have:
myapp -f <(cat)
when I run it I get this error:
You need to pass a file after the -f flag. The resolved file path was: '/dev/fd/63'. This path did not appear to exist on the filesystem.
How can I determine if the result of the process substitution is an actual file (for validation purposes)? Here is my bash code which generated the error:
if [[ -L "$file_path" ]]; then
file_path="$(readlink "$file_path")";
fi
if [[ ! -f "$file_path" ]]; then
echo "You need to pass a file after the -f flag. The resolved file path was: '$file_path'. This path did not appear to exist on the filesystem".;
return 1;
fi
if I get rid of my validation, code, I get this:
Could not open the following file for reading: /dev/fd/63 EBADF: bad file descriptor, open '/dev/fd/63'
The node.js code I am using to read from the path is:
const fd = fs.openSync(file_path, 'r');
fs.read(fd, ...);
[ -f file ]tests iffileis a regular file, and the file created by a process substitution is a pipe, not a regular file. Also, on Linux, the target of a/dev/fd/n->/proc/self/fd/n"symlink" is some informative string liketype:[inum], not a path for pipes, sockets, etc./dev/fd/x, is there some way to do that?node -e 'fs=require("fs"); fs.openSync(process.argv[1], "r")' <(cat /dev/null)works for me.cat <(cat)will not work from console, because thecatinside the process substitution may run in a different process group than the foreground one, and cannot read from the tty./dev/fd/Nare character special files (they aren't regular files, either). And on FreeBSD you should mountfdescfsif you want to access filedescs > 2 via/dev/fd/N.