"< <(command-here)" shell idiom resulting in "redirection unexpected"
Regarding the "redirection unexpected" error:
That's not related to stable
, it's related to your script using /bin/sh
, not bash
. The <()
syntax is unavailable in POSIX shells, which includes bash when invoked as /bin/sh
(in which case it turns off nonstandard functionality for compatibility reasons).
Make your shebang line #!/bin/bash
.
Understanding the < <()
idiom:
To be clear about what's going on -- <()
is replaced with a filename which refers to the output of the command which it runs; on Linux, this is typically a /dev/fd/##
type filename. Running < <(command)
, then, is taking that file and directing it to your stdin... which is pretty close the behavior of a pipe.
To understand why this idiom is useful, compare this:
read foo < <(echo "bar")echo "$foo"
to this:
echo "bar" | read fooecho "$foo"
The former works, because the read is executed by the same shell that later echoes the result. The latter does not, because the read is run in a subshell that was created just to set up the pipeline and then destroyed, so the variable is no longer present for the subsequent echo.
Understanding bash -s stable
:
bash -s
indicates that the script to run will come in on stdin. All arguments, then, are fed to the script in the $@
array ($1
, $2
, etc), so stable
becomes $1
when the script fed in on stdin is run.