💾 Archived View for xoc3.io › blog › 2021-07-27 captured on 2023-04-26 at 13:18:45. Gemini links have been rewritten to link to archived content
⬅️ Previous capture (2022-04-28)
-=-=-=-=-=-=-
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