GNU yes(1)
analogue
#27
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
How should we implement this style of tool?
Implementation ideas include:
echo -r
,-r
being "reverberate", would be delightful, but echo(1p) is implementation dependent enough as-is.speak
has historically been used for text-to-speech, so maybe not the best name under which to put anecho
.Plan 9 from User Space uses an echo (notably, with a
-n
option) and no yes(1) that I can see. I presume yes(1) would be accomplished easily in rc(1). I don't know it but here it is in sh(1):Argument echoing is a tough cookie because so many utilities do it. There are at least four designed for the task; echo(1) (POSIX, but they advise against its use for printf(1p) due to wildly varying implementations), printf(1p), prompt(1) (not POSIX and as far as I know rarely implemented, I'll explain further in the following paragraphs), and yes(1) (not in POSIX). To briefly describe all of them as background:
echo(1p), described in A Research UNIX Reader (pg. 7), prints its arguments to standard output, space-delimited and with a trailing newline.
prompt(1), described in the same paragraph, was replaced with echo(1)'s
-n
option, which is the heritage from which Plan 9's echo(1) derives. It prints without the newline:I really like prompt(1) and it being a separate utility to do this because echo(1) never reliably has any particular option. I've implemented both in C and Rust already but I had trouble with being able to output non-UTF-8 arguments in Rust so if we were to import one of these into the coreutils tree C would be the way to go for now.
printf(1p) is POSIX's answer to echo(1)'s unreliability in arguments. Standardized and based on a standardized language library feature (printf(3p) from the C standard library, particularly
<stdio.h>
), printf(1p) rarely differs in implementation, though its syntax isn't the prettiest:It takes C format strings but with some fiddly bits attached to make it more convenient for shell scripting.
Finally, there's yes(1), which is echo(1) but forever:
The only utility we really need to implement is printf(1p), after which we can write echo(1), prompt(1), and yes(1) in shell. I would prefer echo(1) and prompt(1) to be in C because they're small and easily debugged though any actual benefit from this would be little to none. yes(1) could be easily done in shell as well no matter what's implemented. Its usage in the GNU coreutils seems to be the same as echo(1) (as in, it spits out its arguments space-delimited newline-terminated) but with repetition.
If arguments weren't supported I imagine it would be awkward to bend yes(1) to one's uses:
So I would prefer to just support arguments. It wouldn't really take much more effort. It doesn't seem to have any specific options though GNU yes(1)'s man page is quite short and the GNU website documentation for yes(1) is shorter so I'm not sure.
Here's a fully featured yes(1) in C:
Untested.
printf(1p) will suck to implement so I'll wanna finish what I've already started before that.
i didn’t think we would be including printf? didn’t we discuss a different formatting tool?
printf(1p) would be a nice addition.
On second thought I might be able to implement it in shell without terrible hacks. It seems to do the following:
printf '%d\n' "$var"
). This could be an int(1) or something.Perhaps printf(1) should be a shell script and echo(1), prompt(1), and some others should be binaries?
i think we discussed an out(1) command in the past that does what echo does but without the uncertainty that comes with how it’s defined in POSIX. we definitely want a format(1) command but i want to veto most explicitly posixy tool names in the bonsai coreutils, we want as little semantic overlap with it as possible because we want to make clear that our shell is not POSIX and not POSIX-compliant.
A printf(1p) implementation as one of the test scripts in
tests/posix/
would be ideal.Emma and I just discussed this:
format(1) should be a string formatter akin to printf(1p) but without sucking. out(1) should be a wrapper around format(1) to be an echo(1) equivalent without the POSIX-specified
-n
option. And yes(1) should also be a wrapper around format(1).GNU yes(1) analogueto GNU `yes(1)` analogueOn second thought, I'm fully on board with dropping printf(1p) and using format(1). I wonder if the name could be better though - I still think "format" is vague.
I don't think out(1) is necessary. Even really fresh beginners to C are taught printf(3p) and that requires the newline to be specified.
I still believe yes(1) should be a shell script, wrapping format(1).