Skip to content

connect -- 'cmd; cmd' runs the whole string as a command name (exit 127): #369's fix over-corrected #738

Closed

Description

@scttfrdmn

Reported from the 2026-10-07 demo. Confirmed, with the exact generated argv.

$ spawn connect chem-debug -- 'free -m; tail /var/log/x'
bash: line 1: free -m; tail /var/log/x: No such file or directory   # exit 127

$ spawn connect chem-debug -- tail -25 /var/log/x                   # works

The mechanism

shellQuoteArgs (cmd/connect.go:181) single-quotes each post--- argument
and joins them. Dumping the generated remote command for three inputs:

args=["free -m; tail /var/log/x"]   -> 'free -m; tail /var/log/x'
args=["tail" "-25" "/var/log/x"]    -> 'tail' '-25' '/var/log/x'
args=["bash" "-lc" "a && b"]        -> 'bash' '-lc' 'a && b'

The first is one single-quoted word, so the remote login shell looks for a
command literally named free -m; tail /var/log/x, does not find it, and exits
127. The other two are correct.

This is #369's fix, working as designed, over-correcting

#369 was the opposite bug: the old code space-joined argv into one blob and
re-wrapped it in bash -c '…', so -- bash -lc "a && b" became
bash -c 'bash -lc a && b' and -lc got no argument. Per-argument quoting fixed
that correctly. It just also removed the ability to pass a command string.

Worth noting for whoever fixes this: real ssh does no quoting at all — it
space-joins argv and lets the remote shell re-parse, which is why ssh h bash -lc "a && b" is broken for ssh too, and why everyone single-quotes for ssh. So
"behave like ssh" and "keep #369 fixed" are in tension if taken literally. They
are reconcilable by looking at the argument count.

Suggested fix

Branch on len(args) after --:

Both forms then work, and the rule is explainable in one sentence: one argument is
a shell command line, several arguments are an argv.

A regression test should pin both directions, since this is now the second
time one was fixed by breaking the other:

{"free -m; tail /x"}          -> free -m; tail /x
{"bash", "-lc", "a && b"}     -> 'bash' '-lc' 'a && b'

cmd/connect_oneshot_test.go is the natural home, and it already covers the #369
case.

Severity: low — the multi-word form works and is documented. But exit 127 with a
No such file or directory naming the user's whole command reads like the remote
box is broken, which costs more debugging time than the bug deserves.

Environment: spawn v0.123.0.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions