Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/uu/env/locales/en-US.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ env-error-use-s-shebang = use -[v]S to pass options in shebang lines
env-error-cannot-unset = cannot unset '{ $name }': Invalid argument
env-error-cannot-unset-invalid = cannot unset { $name }: Invalid argument
env-error-must-specify-command-with-chdir = must specify command with --chdir (-C)
env-error-must-specify-command-with-argv0 = must specify command with --argv0 (-a)
env-error-cannot-change-directory = cannot change directory to { $directory }: { $error }
env-error-argv0-not-supported = --argv0 is currently not supported on this platform
env-error-failed-set-signal-action = failed to set signal action for signal { $signal }: { $error }
Expand Down
9 changes: 9 additions & 0 deletions src/uu/env/src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -814,6 +814,15 @@ impl EnvAppData {
}
}

// GNU env requires a command when --argv0 is given. Validate before
// apply_change_directory performs its side effect.
if opts.program.is_empty() && opts.argv0.is_some() {
return Err(UUsageError::new(
125,
translate!("env-error-must-specify-command-with-argv0"),
));
}

apply_change_directory(&opts)?;
if opts.program.is_empty() {
// no program provided, so just dump all env vars to stdout
Expand Down
11 changes: 11 additions & 0 deletions tests/by-util/test_env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,17 @@ fn test_fail_change_directory() {
assert!(out.contains("env: cannot change directory to "));
}

#[test]
fn test_argv0_without_command_fails() {
for arg in ["-a", "--argv0"] {
let out = new_ucmd!()
.args(&[arg, "foo"])
.fails_with_code(125)
.stderr_move_str();
assert!(out.contains("must specify command with --argv0 (-a)"));
}
}

#[cfg(not(windows))] // windows has no executable "echo", its only supported as part of a batch-file
#[test]
fn test_split_string_into_args_one_argument_no_quotes() {
Expand Down
Loading