=> back to xoc3.io

2021-07-27 - here documents & here strings

this is a bash post. i knew about here documents in bash, but i didn't know what it is called. a here document is something like this:

cat << eof
hello world
eof

it tells bash to redirect the current input to stdin, until you reach the token defined right after the <<. but the other day i wanted to replace stdin with the content of an environment variable. the approach i came up with was:

avar="hello world"
echo "$avar" | cat

but there is another, arguably better, way to do that with a here string:

avar="hello world"
cat <<< $avar

i never noticed the <<< here string syntax before, so i thought i'd share. you can find some more information on here strings and here documents here:

=> http://www.gnu.org/savannah-checkouts/gnu/bash/manual/bash.html#Here-Documents

Proxy Information
Original URL
gemini://xoc3.io/blog/2021-07-27
Status Code
Success (20)
Meta
text/gemini;charset=UTF-8
Capsule Response Time
633.777407 milliseconds
Gemini-to-HTML Time
0.236805 milliseconds

This content has been proxied by September (3851b).