Re: [PATCH 1/4] t0021: use write_script to create rot13 shell script
- From
Lars Schneider <larsxschneider@gmail.com>
- Date
- Nov 6, 2016, 14:43 UTC
- Message-ID
- <65249E23-8685-44A8-B2AC-9C414658540E@gmail.com>
- In-Reply-To
- <20161106142957.52wx2llanw5bis4i@sigill.intra.peff.net>
Show 25 quoted lines
> On 06 Nov 2016, at 15:29, Jeff King <peff@peff.net> wrote:
>
> On Sun, Nov 06, 2016 at 03:25:33PM +0100, Lars Schneider wrote:
>
>> This looks good to me (and it works on my machine).
>> However, I took a look at the "write_script" function and found this,
>> added by Junio in 840c519d:
>>
>> echo "#!${2-"$SHELL_PATH"}" &&
>>
>> There is some kind of variable expansion happening with the "2-" but
>> I can't quite figure out what is going on. Plus, I can't find anything
>> about this in the sh docs.
>>
>> Can anyone help me to understand it?
>
> See the section on parameter expansion in "man bash". Basically:
>
> ${foo:-bar}
>
> expands to $foo, or "bar" if it is unset or empty. Without the colon:
>
> ${foo-bar}
>
> expands to $foo, "bar" if it unset (but not if it is empty).Ahh! The missing colon tricked me. For some reason the version without colon is not mentioned in my docs (GNU bash, version 3.2.57) or I overlooked it.
Thanks for taking the time to explain it!
- Lars