Bash syntax mapfile input redirection

Can someone explain me this syntax for redirecting mapfile input?

mapfile -t array < <(./inner.sh) 

(from https://stackoverflow.com/a/3129479/) from gniourf_gniourf)

As I understand it, the first "<" is to accept input from what is on the right side. But what is the syntax <(...)? Why is the second "<" required?

+7
redirect input bash
source share
1 answer

The reason for the related example is as follows:

 wc <(cat /usr/share/dict/linux.words) 

And the mapfile answer is as follows:

 mapfile -t array < <(./inner.sh) 

Due to the difference in wc and mapfile and how the replaced process should be specified for the command.

As anishsane says, the extension <(command) is a file name and can be used wherever a file name can be used.

wc accepts file names as arguments, so they can be used directly as an argument.

mapfile is read from standard input, so to read it from the specific file you are using, you redirect standard input from the file </path/to/somefile , but, as I said, the extension <(command) is the name of the file, so you can use that in input redirect.

However, you cannot just pass two bits directly (the way you can with the file name / path), because << also a valid shell construct (here is a document), and this will be ambiguous for the shell. Therefore, in order to avoid the fact that you need to select two characters < and the result is < <(command) (which is similar to < file , which is completely legal).

+10
source share

All Articles