[Top][All Lists]

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

Re: Feature Request: scanf-like parsing

From: Léa Gris
Subject: Re: Feature Request: scanf-like parsing
Date: Fri, 22 Jan 2021 19:18:41 +0100
User-agent: Telnet/1.0 [tlh] (PDP11/DEC)

Le 22/01/2021 à 18:55, Greg Wooledge écrivait :
It's not hard at all.  People just have a deep, almost religious, loathing
against creating their own temp files.

And yet, these same people are*perfectly*  happy if some tool creates
a temp file for them -- as long as they don't have to see any of the
details or do any of the work.

Because handling a temp file properly is already a bit of additional implementation that involves using trap for cleanup. Handling multiple tempfiles with proper cleanup becomes a complex unreliable task if implemented with Bash script commands.

So if a syntactic sugar does it all properly, safely and with proper cleanup then it is good.

You could always implement the equivalent of:

read -r variable < <(command)

with creating a temporary fifo:

fifo=$(mktemp --dry-run)
trap 'rm -f "$fifo"' EXIT
mkfifo "$fifo" || exit 1
compgen -u >"$fifo" &
mapfile -t users <"$fifo"

But I really prefer this way because it is safer and much more reliable:
mapfile -t users < <(compgen -u)

Now replace the the () with {}, replace the implicit temporary fifo by and implicit temporary file; then have the same feature but without spawning a sub-shell.

Léa Gris

reply via email to

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