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.