Page MenuHomeFreeBSD

echo(1): Add EXAMPLES
ClosedPublic

Authored by fernape on Jan 18 2024, 11:22 AM.
Tags
None
Referenced Files
Unknown Object (File)
Sun, Nov 10, 4:11 PM
Unknown Object (File)
Sat, Nov 9, 4:11 PM
Unknown Object (File)
Fri, Nov 8, 6:47 AM
Unknown Object (File)
Fri, Nov 8, 6:47 AM
Unknown Object (File)
Fri, Nov 8, 2:27 AM
Unknown Object (File)
Wed, Nov 6, 9:27 PM
Unknown Object (File)
Tue, Nov 5, 8:00 AM
Unknown Object (File)
Thu, Oct 17, 11:49 AM

Details

Summary

Add some examples to the manual page.

Test Plan

Apply patch and view manual page.

igor, vale and mandoc -T lint are OK with the change

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 55497
Build 52386: arc lint + arc unit

Event Timeline

pauamma_gundo.com added inline comments.
bin/echo/echo.1
95–96
[pauamma@Pusat-Tasek] ~% /bin/echo "-hello\\tworld"
-hello\\tworld

Note the double backslash, compared to the single one in your example output.

101

Is there a reason to use the builtin echo for the 2nd invocation?

107

Same question here, plus spurious space before ;

[pauamma@Pusat-Tasek] ~% /bin/echo "hello\\c" ;echo world
hello\world

Note the backslash in the output, vs. none in your example output.

I'd be more likely to suggest people use the more portable constructs available from printf(1).

bin/echo/echo.1
95–96

This is a difference between /bin/sh and /bin/csh and quoting rules.
If you do it inside of /bin/sh, then you get this output.

fernape added inline comments.
bin/echo/echo.1
95–96

But that is not what the user sees. Please, render the manpage with man ./echo.1. The first backslash is for mandoc. This is what is rendered:

Special treatment of options and backslashes:

      $ /bin/echo "-hello\tworld" <---- Just \t not \\t
      -helloworld
95–96

Yes, the examples use sh

107

Ditto, this is what the user sees when the manual page is rendered:

Or to achieve the same result:

      $ /bin/echo "hello\c" ;echo world
      helloworld
In D43493#991914, @imp wrote:

I'd be more likely to suggest people use the more portable constructs available from printf(1).

printf(1) is mentioned in the SEE ALSO section. Do you mean an additional note reinforcing the idea of using printf(1) instead of echo(1)?

In D43493#991914, @imp wrote:

I'd be more likely to suggest people use the more portable constructs available from printf(1).

printf(1) is mentioned in the SEE ALSO section. Do you mean an additional note reinforcing the idea of using printf(1) instead of echo(1)?

Yes. I'm of the opinion that echo should not be used any time you want the output to be exactly "just so" because other implementations don't do the \X expansion quite right, or they don't recognize the command switches to not do newline. And it's not even portable between /bin/echo and sh(1) builtin-echo on FreeBSD. For those times, you should use printf(1). It's also builtin to shell and any performance difference between echo and printf is going to be in the noise.

Add CAVEATS section to promote the use of printf(1)

This revision is now accepted and ready to land.Jan 20 2024, 4:04 AM

I'm more concerned that uses of echo are also non-portable to other systems.
The difference between /bin/sh and /bin/csh are likely not that interesting because almost nobody writes csh scripts.
printf is portable and the same everywhere (more or less), but echo is eccentrically different.

Remove reference to differences between shells.
Focus on portability issues.

This revision now requires review to proceed.Jan 20 2024, 5:40 PM

English nitpicks fixable on commit.

bin/echo/echo.1
129
136

Or are the two shortcomings only one?

This revision is now accepted and ready to land.Jan 20 2024, 9:14 PM
This revision now requires review to proceed.Jan 22 2024, 9:19 AM
gbe added a subscriber: gbe.

LGTM

This revision is now accepted and ready to land.Mar 18 2024, 6:22 PM
This revision was automatically updated to reflect the committed changes.

Thank you all for the review.