Skip to content

Commit

Permalink
Merge pull request #6810 from cakebaker/echo_remove_double_negation
Browse files Browse the repository at this point in the history
echo: remove double negation
  • Loading branch information
tertsdiepraam authored Oct 23, 2024
2 parents 7de3700 + 13df9e2 commit 6850be2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
10 changes: 5 additions & 5 deletions src/uu/echo/src/echo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
// "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."
// https://www.gnu.org/software/coreutils/manual/html_node/echo-invocation.html

let no_newline = matches.get_flag(options::NO_NEWLINE);
let trailing_newline = !matches.get_flag(options::NO_NEWLINE);
let escaped = matches.get_flag(options::ENABLE_BACKSLASH_ESCAPE);

let mut stdout_lock = io::stdout().lock();
Expand All @@ -291,14 +291,14 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
Some(arguments_after_options) => {
execute(
&mut stdout_lock,
no_newline,
trailing_newline,
escaped,
arguments_after_options,
)?;
}
None => {
// No strings to print, so just handle newline setting
if !no_newline {
if trailing_newline {
stdout_lock.write_all(b"\n")?;
}
}
Expand Down Expand Up @@ -350,7 +350,7 @@ pub fn uu_app() -> Command {

fn execute(
stdout_lock: &mut StdoutLock,
no_newline: bool,
trailing_newline: bool,
escaped: bool,
arguments_after_options: ValuesRef<'_, OsString>,
) -> UResult<()> {
Expand All @@ -375,7 +375,7 @@ fn execute(
}
}

if !no_newline {
if trailing_newline {
stdout_lock.write_all(b"\n")?;
}

Expand Down
7 changes: 1 addition & 6 deletions tests/by-util/test_echo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,7 @@ fn test_default() {

#[test]
fn test_no_trailing_newline() {
new_ucmd!()
.arg("-n")
.arg("hi")
.succeeds()
.no_stderr()
.stdout_only("hi");
new_ucmd!().arg("-n").arg("hi").succeeds().stdout_only("hi");
}

#[test]
Expand Down

0 comments on commit 6850be2

Please sign in to comment.