Here's an interesting Bash pattern I just used for the first time.
-
Here's an interesting Bash pattern I just used for the first time.
some-command <<<"$(< some/file)" >some/file
It reads all of some/file into memory before writing it to some-command's stdin. This lets some-command's stdout be redirected to some/file without the usual problems of reading/writing from the same file.
-
@trs thanks for that - I learned two new bits of Bash I hadn't seen before: <<<"string" and $(< file), both of which I now know are slightly more efficient than the cat-pipe equivalents because they don't have to launch an additional process
Copyright © 2024 NodeBB | Contributors