Skip to content

Commit 6850be2

Browse files
Merge pull request #6810 from cakebaker/echo_remove_double_negation
echo: remove double negation
2 parents 7de3700 + 13df9e2 commit 6850be2

File tree

2 files changed

+6
-11
lines changed

2 files changed

+6
-11
lines changed

src/uu/echo/src/echo.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
282282
// "If the POSIXLY_CORRECT environment variable is set, then when echo’s first argument is not -n it outputs option-like arguments instead of treating them as options."
283283
// https://www.gnu.org/software/coreutils/manual/html_node/echo-invocation.html
284284

285-
let no_newline = matches.get_flag(options::NO_NEWLINE);
285+
let trailing_newline = !matches.get_flag(options::NO_NEWLINE);
286286
let escaped = matches.get_flag(options::ENABLE_BACKSLASH_ESCAPE);
287287

288288
let mut stdout_lock = io::stdout().lock();
@@ -291,14 +291,14 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
291291
Some(arguments_after_options) => {
292292
execute(
293293
&mut stdout_lock,
294-
no_newline,
294+
trailing_newline,
295295
escaped,
296296
arguments_after_options,
297297
)?;
298298
}
299299
None => {
300300
// No strings to print, so just handle newline setting
301-
if !no_newline {
301+
if trailing_newline {
302302
stdout_lock.write_all(b"\n")?;
303303
}
304304
}
@@ -350,7 +350,7 @@ pub fn uu_app() -> Command {
350350

351351
fn execute(
352352
stdout_lock: &mut StdoutLock,
353-
no_newline: bool,
353+
trailing_newline: bool,
354354
escaped: bool,
355355
arguments_after_options: ValuesRef<'_, OsString>,
356356
) -> UResult<()> {
@@ -375,7 +375,7 @@ fn execute(
375375
}
376376
}
377377

378-
if !no_newline {
378+
if trailing_newline {
379379
stdout_lock.write_all(b"\n")?;
380380
}
381381

tests/by-util/test_echo.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,7 @@ fn test_default() {
1313

1414
#[test]
1515
fn test_no_trailing_newline() {
16-
new_ucmd!()
17-
.arg("-n")
18-
.arg("hi")
19-
.succeeds()
20-
.no_stderr()
21-
.stdout_only("hi");
16+
new_ucmd!().arg("-n").arg("hi").succeeds().stdout_only("hi");
2217
}
2318

2419
#[test]

0 commit comments

Comments
 (0)