Re: [PATCH v12 1/5] t0040-test-parse-options.sh: fix style issues
- From
Eric Sunshine <sunshine@sunshineco.com>
- Date
- Apr 4, 2016, 17:30 UTC
- Message-ID
- <CAPig+cQw=aG0NOgEsmdTGc7v3iBA-qG9_C4EdSm=6PcE6Qn-uQ@mail.gmail.com>
- In-Reply-To
- <CAFZEwPNaxFyFmCkvPjRZQ0grOm1oWB1+5QhkpOMyEKW7j_99qQ@mail.gmail.com>
On Mon, Apr 4, 2016 at 8:45 AM, Pranit Bauva <pranit.bauva@gmail.com> wrote:
Show 8 quoted lines
> Okay I will do the change. I was previously unaware about the use of > '\' before EOF. I googled it now. But I am still confused about its > use in this scenario. Upto what I understood, it is used where you > want to expand a variable, substitute a command, arithmethic > expansion. The use of '\' in the tests I have changed in v12 wrt 11 is > understood by me as you want to remove the use of escape sequences > which is justified. But this seems a bit vague. Is it some convention > in git?
Both 'EOF' and \EOF suppress interpolation and other transformations in the heredoc content which would otherwise occur with plain EOF. The 'EOF' form is well documented; \EOF not so much, but is used heavily in git test scripts. So:
x=flormp
echo <<EOF
Hello, $x
EOFprints "Hello, flormp", whereas:
echo <<\EOF
Hello, $x
EOFprints "Hello, $x".
While test scripts sometimes use \EOF to explicitly suppress variable expansion, it's also quite common to use it even when there is nothing which could be expanded in the heredoc content, in which case it signals to the reader that the author doesn't expect the content to undergo expansion or interpolation. It's also a bit of future-proofing in case some later change to the heredoc content inserts something which might otherwise be expanded.