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,793
  • 1
  • 12
  • 16

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
  • 242,166