27

This answer on Security StackExchange uses an interesting bash syntax to generate a file in-line:

openssl req -new -x509 -nodes -newkey ec:<(openssl ecparam -name secp384r1) -keyout cert.key -out cert.crt -days 3650

This bit is particularly interesting:

<(openssl ecparam -name secp384r1)

Running just:

echo <(openssl ecparam -name secp384r1)

I get back /dev/fd/63

So this seems to make a temporary file descriptor with the file's contents.

What is this called?

mikemaccana
  • 1,723
  • 1
  • 12
  • 16
  • 3
    Note that the resulting "file" is actually a named pipe, and some programs don't support them as file arguments. Example: `git diff --no-index file1 <(cat file2)` will fail with: `error: /dev/fd/63: unsupported file type`. You might also see `error: readlink("/dev/fd/63"): No such file or directory` if the implementation creates a symlink to the pipe (appears as a broken link for me for some reason). – Kelvin Jul 08 '16 at 16:27
  • 1
    Related: [What are the shell's control and redirection operators?](//unix.stackexchange.com/q/159513/80216) and [What does a “< <(…)” redirection mean?](//unix.stackexchange.com/q/22645/80216) – G-Man Says 'Reinstate Monica' Jul 09 '16 at 03:32

1 Answers1

37

It's called process substitution and is a feature of bash, zsh and ksh (and possibly others, I don't know). It isn't POSIX and you shouldn't use it in portable code, but it's very useful.

Here's the relevant section of the bash manual:

3.5.6 Process Substitution

Process substitution is supported on systems that support named pipes (FIFOs) or the /dev/fd method of naming open files. It takes the form of

  <(list) 

or

  >(list) 

The process list is run with its input or output connected to a FIFO or some file in /dev/fd. The name of this file is passed as an argument to the current command as the result of the expansion. If the >(list) form is used, writing to the file will provide input for list. If the <(list) form is used, the file passed as an argument should be read to obtain the output of list. Note that no space may appear between the < or > and the left parenthesis, otherwise the construct would be interpreted as a redirection.

When available, process substitution is performed simultaneously with parameter and variable expansion, command substitution, and arithmetic expansion.

terdon
  • 234,489
  • 66
  • 447
  • 667