[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: "here strings" and tmpfiles

From: Greg Wooledge
Subject: Re: "here strings" and tmpfiles
Date: Thu, 11 Apr 2019 08:42:48 -0400
User-agent: Mutt/1.10.1 (2018-07-13)

On Thu, Apr 11, 2019 at 06:02:41AM +0200, Jason A. Donenfeld wrote:
> what about internally treating "x <<y" as "echo y |
> x"? Are these somehow not quite equivalent because x is in a subshell
> in one but not the other, or something like that?

cmd <<< string   opens a temporary file for writing, dumps the string
plus a newline to the temporary file, reopens the temporary file for
reading as file descriptor 0 (stdin), and then runs cmd.  If you want
only string (no newline) to be written, you cannot use this approach.

printf %s string | cmd    forks two subshells (or one if lastpipe is
enabled) with an anonymous pipe between them.  The first subshell runs
printf, and the second subshell runs cmd.  If you want to add a newline,
you may use '%s\n' instead of %s.  The subshell(s) are run as a single
"job" (process group) for job control purposes, unless monitor mode is

cmd < <(printf %s string)   runs printf in a background subshell, and cmd
as a foreground command.  Bash will use either a named pipe or a /dev/fd/
entry to connect them, depending on the platform.

And, of course, you may always explicitly create your own temporary file
and write whatever you like into it (newlines or not); or explicitly
create your own named pipe and launch processes reading/writing from it
however you wish.

I do not believe it would be a wise decision to "internally treat <<<
like a pipeline", because that removes one of the choices in the
script writer's toolbox.  If you don't like the semantics or the
implementation of your chosen tool, choose a different one.

Reducing the toolbox because 3 people out of the entire planet decided
to pass passwords via <<< without knowing how <<< works seems like a
really poor idea to me.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]