Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does "< <(command args)" mean in the shell?

When looping recursively through folders with files containing spaces the shell script I use is of this form, copied from the internet:

    while IFS= read -r -d $'\0' file; do       dosomethingwith "$file"        # do something with each file     done < <(find /bar -name *foo* -print0) 

I think I understand the IFS bit, but I don't understand what the '< <(...)' characters mean. Obviously there's some sort of piping going on here.

It's very hard to Google "< <" or "<(", you see. I tried "angle bracket parenthesis" and "less-than parenthesis" but didn't find anything.

like image 411
stib Avatar asked Mar 14 '10 17:03

stib


People also ask

What is command line arguments in shell?

Overview : Command line arguments (also known as positional parameters) are the arguments specified at the command prompt with a command or script to be executed. The locations at the command prompt of the arguments as well as the location of the command, or the script itself, are stored in corresponding variables.

What is the meaning of $# and $@ With regard to command line arguments?

"$@" Stores all the arguments that were entered on the command line, individually quoted ("$1" "$2" ...). So basically, $# is a number of arguments given when your script was executed.

How do you read arguments in a shell program?

The special character $# stores the total number of arguments. We also have $@ and $* as wildcard characters which are used to denote all the arguments. We use $$ to find the process ID of the current shell script, while $? can be used to print the exit code for our script.

What does $? Mean shell script?

Show activity on this post. echo $? - Gives the EXIT STATUS of the most recently executed command . This EXIT STATUS would most probably be a number with ZERO implying Success and any NON-ZERO value indicating Failure.


1 Answers

<() is called process substitution in the manual, and is similar to a pipe but passes an argument of the form /dev/fd/63 instead of using stdin.

< reads the input from a file named on command line.

Together, these two operators function exactly like a pipe, so it could be rewritten as

find /bar -name *foo* -print0 | while read line; do   ... done 
like image 57
Josh Lee Avatar answered Sep 30 '22 22:09

Josh Lee