handling quoted arguments
- Dominant language
- Go
- Stars
- 28
- Forks
- 4
- PR merge metrics
- No merged PRs in 30d
Description
Consider a shell command:
```
$ foobar arg1 "this is arg2" arg3
```
When it comes to the syscall that executes a program, arguments are represented as structured data: an array. In this case, we'd expect an array of 3 elements, the second having spaces. (Technically, 4 elements, the first being the program name)
When the program gets these arguments, the quotes are not there. The quotes are an artifact of the shell as a solution to interpreting arguments with spaces, since obviously spaces are used to separate arguments. Quoting is a POSIX standard, but different shells can achieve quoting in lots of different ways. For example, imagine a shell that is more like a modern programming REPL and arguments are separated by commas.
For whatever reason, the SSH protocol was not implemented with an awareness of structured arguments. The command above would be encoded as a string `foobar arg1 this is arg2 arg3`.
We perform POSIX lexing on the receiving end, but by then we've lost the quotes. In order to get around this, we can double quote:
```
$ ssh server.com foobar arg1 '"this is arg2"' arg3
```
Which is encoded as `foobar arg1 "this is arg2" arg3`. You might think, wait how do we do this normally with SSH? What's typical is to quote the whole command string, and quoting within it, because it's understood that we're encoding a string representing the command to execute on the other end and the other end will parse it *depending on the shell* it's run through.
```
$ ssh server.com "foobar arg1 'this is arg2' arg3"
```
This conceptual model makes sense traditionally. However, the expectations cmd.io sets up are different. We treat it almost like a local CLI client. We expect this to work:
```
$ ssh cmd.io foobar arg1 "this is arg2" arg3
```
But it doesn't. We could suggest either of the above double quoting workarounds, however, I think this will be common enough that it would intrude on the expectation/illusion we're trying to maintain.
My proposed solution is to provide an alternative to argument quoting:
```
$ ssh cmd.io foobar arg1 [this is arg2] arg3
```
This will be encoded as `foobar arg1 [this is arg2] arg3`, which we can then parse into proper arguments. POSIX shells don't treat `[]` as special characters and probably never will because of the `[` and `[[` "commands". In the rare case this is not possible for a user (using some weird shell that uses `[]`), we can then suggest double quoting.
Thoughts?
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.