git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Shell quoting

From
HAH. Peter Anvin <hpa@zytor.com>
Date
Sep 15, 2005, 18:44 UTC
Message-ID
<4329C11A.1040302@zytor.com>
In-Reply-To
<7vy85yahjk.fsf@assigned-by-dhcp.cox.net>
Okay, I'm trying to put together some rules that should work across shells.
For byte values:
0		Hopeless - not representable in C strings
1-31,127	Prefix with ^V if (and only if!) entered at a prompt,
		as opposed to passed in the ssh command field
32-126		\-escape all characters except -+_@=:.,/ and
  		ASCII alphanumerics
128-		Don't escape (would have to be done differently
  		depending on locale, and shouldn't be needed)

Anyone know of a system for which that breaks horribly? The 1-31,127 stuff is iffy, but I just don't know of anything that's more reliable. Unfortunately \010-style quoting doesn't work in any of the common shells.

	-hpa
Previous: H. Peter AnvinNext: Linus Torvalds
Message 4 of 12 in “Remove shell dependency in env.c”
  1. Remove shell dependency in env.cH. Peter Anvin, Sep 15, 2005
  2. Junio C HamanoSep 15, 2005
  3. H. Peter AnvinSep 15, 2005
  4. Shell quotingH. Peter Anvin, Sep 15, 2005
  5. Linus TorvaldsSep 15, 2005
  6. H. Peter AnvinSep 15, 2005
  7. Junio C HamanoSep 15, 2005
  8. H. Peter AnvinSep 15, 2005
  9. Junio C HamanoSep 15, 2005
  10. Linus TorvaldsSep 15, 2005
  11. Junio C HamanoSep 16, 2005
  12. rsh.c env and quoting cleanup, take 2H. Peter Anvin, Sep 15, 2005

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.