Skip to content

Quote arguments when printing a multi-argument sh command - #787

Open
adityawrk wants to merge 1 commit into
ruby:masterfrom
adityawrk:fix/quote-sh-command
Open

adityawrk wants to merge 1 commit into
ruby:masterfrom
adityawrk:fix/quote-sh-command

Conversation

@adityawrk

@adityawrk adityawrk commented Nov 29, 2026 •

Copy link
Copy Markdown

sh with several arguments runs them directly, without a shell. The line it prints was cmd.join(" "), so an argument that contained a space was shown as two words. The process still received the original argument.

sh "ruby", "extconf.rb", "--", "--with-cflags=-Wundef -Werror"

Before, that printed:

ruby extconf.rb -- --with-cflags=-Wundef -Werror

Pasting that line back into a shell splits -Werror into its own argument. The same call now prints a shell-quoted command, and Shellwords.split returns the original argument list, including --with-cflags=-Wundef -Werror. Environment values are quoted the same way (CFLAGS=-Wundef -Werror stays one assignment).

A single string is still a shell command line (sh "echo hello | wc") and is printed unchanged.

Fixes #501.

sh prints the command it is about to run. With several arguments it
joined them with spaces, so an argument that contained a space looked
like two arguments. The process itself was started with the original
argument list, so the printed line was not the command that ran.

Shell-escape each argument of a multi-argument command, and each
environment value. A single string is still a shell command line and
is printed unchanged.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

sh_show_command: Quotes are missing for an extra option including a space.

1 participant