No, < <
and <<
are not the same thing.
The first is composed of the common <
redirection character combined with the first character of the <(command)
syntax. This is a ksh
construct (also found in bash
and zsh
) known as process substitution that takes the output of command
and provides it in a file whose name refers to the other end of the pipe command
is writing to.
In other word you can think of < <(command)
as < file
, where file contains the output of command
.
Let's break this down into pieces.
This code runs the command :
with some arguments. The command :
does nothing and ignores its arguments. Therefore the whole command line does nothing, except whatever side effects happen in the arguments.
The syntax ${parameter_name:=value}
exists in all non-antique Bourne-style shells, including ash, bash, ksh and zsh. It sets the parameter to a default if necessary. It is equivalent to
if [ -z "$parameter_name" ]; then parameter_name=value; fi
… ${parameter_name}
In other words, if parameter_name
is not set or is set to an empty value, then set it to the indicated value; and then run the command, using the new parameter value. There is a variant, ${parameter_name=value}
, which leaves the parameter empty if it was empty, only using the indicated value if the parameter was unset.
You'll find this syntax documented under “parameter expansion” in the POSIX spec, and the dash, bash, ksh and zsh manuals.
There are variations on this syntax, in particular ${parameter_name:-value}
which let you use a default value for this expansion only, without assigning to the parameter.
In summary, : ${parameter_name:=value}
is a concise way of writing
if [ -z "$parameter_name" ]; then parameter_name=value; fi
Best Answer
A redirection
<"dir/file"
opens the file for reading on standard input for the duration of the command that the redirection applies to. When there is no command, the file is open for reading (which leads to an error if the file doesn't exist or lacks proper permission), but other than that the redirection has no effect.Ksh added an extension, which has been adopted by bash and ksh. If a command substitution contains an input redirection and nothing else
$(<"dir/file")
(no command, no other redirection, no assignment, etc.), then the command susbtitution is replaced by the content of the file. Thus$(<"dir/file")
is equivalent to$(cat "dir/file")
(except that it doesn't call thecat
utility, so it's marginally faster and does the same thing even ifcat
has been replaced or isn't in the command search path).This is mentioned in the bash manual under “command substitution”.