Discussion:
Bash syntax for using here-doc's or variables as files in process substitution
(too old to reply)
Jesse Hathaway
2018-06-26 18:42:24 UTC
Permalink
I would love to have native bash support for using a variable or a here doc as
file in process substituion, rather than doing something like this:

cat <(cat <<-'EOF'
butter
EOF
)

printf -v bubbles 'bubbles'
cat <(cat <<<"${bubbles}")
João Eiras
2018-06-26 18:54:39 UTC
Permalink
Maybe...

exec {fd}<<<"long string"
some-command <&$fd
some-command /dev/fd/$fd # < not entirely portable I think
exec {fd}<&-
Jesse Hathaway
2018-06-27 14:35:59 UTC
Permalink
Thanks, João
Post by João Eiras
exec {fd}<<<"long string"
some-command <&$fd
some-command /dev/fd/$fd # < not entirely portable I think
exec {fd}<&-
that definitely works:

printf -v bubbles 'bubbles'
exec {fd}<<<"${bubbles}"
cat <&$fd
exec {fd}<&-

exec {fd}<<-'EOF'
butter
EOF
cat <&$fd
exec {fd}<&-

I would love something that doesn't requiring managing file
descriptors, but this
is certainly a workable solution.
João Eiras
2018-06-27 20:00:59 UTC
Permalink
Post by Jesse Hathaway
I would love something that doesn't requiring managing file
descriptors, but this
is certainly a workable solution.
You will always need to pass some sort of file descriptor to your
sub-process, so you can do that implicitly with some process
substitution or explicitly with exec while avoiding an extra process.
Jesse Hathaway
2018-06-27 20:27:24 UTC
Permalink
Post by João Eiras
You will always need to pass some sort of file descriptor to your
sub-process, so you can do that implicitly with some process
substitution or explicitly with exec while avoiding an extra process.
right, I thought it might be nice to have syntax which allows an
implicit passing, perhaps something like:

cat <(<<<"bubbles")
cat <(<<'EOF'
bubbles
EOF
)

This syntax is apparently supported by zsh in my testing, which I did
not realize
until now.
João Eiras
2018-06-27 21:52:31 UTC
Permalink
Post by Jesse Hathaway
Post by João Eiras
You will always need to pass some sort of file descriptor to your
sub-process, so you can do that implicitly with some process
substitution or explicitly with exec while avoiding an extra process.
right, I thought it might be nice to have syntax which allows an
cat <(<<<"bubbles")
cat <(<<'EOF'
bubbles
EOF
)
I just tried and the syntax can be collapsed a bit, but again use of
/dev/fd is not that portable.

cat /dev/fd/$fd 0<&- {fd}<<<"asd"

Loading...