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

Re: [PATCH 1/2] CodingGuidelines: Add a note about spaces after redirection

From
Junio C Hamano <gitster@pobox.com>
Date
Feb 27, 2012, 18:55 UTC
Message-ID
<7vy5ro85sv.fsf@alter.siamese.dyndns.org>
In-Reply-To
<1330117921-8257-1-git-send-email-tim.henigan@gmail.com>
Tim Henigan <tim.henigan@gmail.com> writes:
Show 5 quoted lines
> + - Redirection operators should be written with space before, but
> +   no space after them.  For example:
> +      'echo test >$file'  is preferred over
> +      'echo test > $file'
> +

If you are using a $file placeholder, then we would need to show readers that they need to be enclosed in dq to prevent some versions of bash from giving us a false warning, and explicitly say why.

  $ bash
  bash$ file='/var/tmp/f i l e'
  bash$ >$file
  bash: $file: ambiguous redirect
  bash$ >"$file"
  bash$ ls -1 "$file"
  /var/tmp/f i l e

Adding something like this after your two line examples, after updating them to use "$file" instead, should be sufficient:

	Note that even though it is not required by POSIX to double quote
	the redirection target in a variable like the above example, our
	code does so because some versions of bash issue an warning unless
	we do.
Previous: Junio C Hamano
Message 4 of 4 in “CodingGuidelines: Add a note about spaces after redirection”
  1. 1/2 CodingGuidelines: Add a note about spaces after redirectionTim Henigan, Feb 24, 2012
  2. 2/2 CodingGuidelines: Add note forbidding use of 'which' in shell scriptsTim Henigan, Feb 24, 2012
  3. Junio C HamanoFeb 27, 2012
  4. Junio C HamanoFeb 27, 2012

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.