On Wednesday, August 27, 2025, Kevin Pulo <kevin.p...@mongodb.com> wrote:

> I would still have to tell people
> "don't use $(), always do some_command > $tmpfile", which isn't much better
> than what I'm trying to avoid ("don't use $(), always use shopt -o
> lastpipe and
> do some_command | grab_output varname").  It's also counter-intuitive to
> read
> instructions which say "redirect to a file and then inspect the file is
> okay,
> but capturing output via $() and then inspecting it isn't okay".
>
> It's still awkward to inspect the $tmpfile (at least within the shell),
> because
> the natural way to do that is $(<$tmpfile)... which still eats the trailing
> newlines.  Meaning I would be back to doing things like read -rd '', which
> even
> if hidden inside a grab_output style helper, isn't idiomatic.
>
> Lesser concerns are that it also assumes a writable $TMPDIR, and the extra
> filesystem involvement can affect performance.
>

Hmm. How much control do you have on the input format? If it's not too
late, rather than swimming against the current maybe you should alter the
input so it can be easily parsed by a POSIX shell


-- 
Oğuz

Reply via email to