diff --git a/src/uu/sort/src/sort.rs b/src/uu/sort/src/sort.rs index e619141005..63c2a73355 100644 --- a/src/uu/sort/src/sort.rs +++ b/src/uu/sort/src/sort.rs @@ -1026,6 +1026,14 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { } }; + // Add check for multiple output files early in the function + if matches.get_many::(options::OUTPUT).map_or(0, |v| v.count()) > 1 { + return Err(USimpleError::new( + 1, + "multiple output files specified" + )); + } + settings.debug = matches.get_flag(options::DEBUG); // check whether user specified a zero terminated list of files for input, otherwise read files from args @@ -1417,7 +1425,8 @@ pub fn uu_app() -> Command { .long(options::OUTPUT) .help("write output to FILENAME instead of stdout") .value_name("FILENAME") - .value_hint(clap::ValueHint::FilePath), + .value_hint(clap::ValueHint::FilePath) + .action(ArgAction::Append), ) .arg( Arg::new(options::REVERSE)