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

Re: [PATCH 1/4] t0021: use write_script to create rot13 shell script

From
Lars Schneider <larsxschneider@gmail.com>
Date
Nov 6, 2016, 14:25 UTC
Message-ID
<22DAA280-1857-4E22-914A-1208D784DA98@gmail.com>
In-Reply-To
<20161102181751.trxsns5pxqk73ukc@sigill.intra.peff.net>
Show 32 quoted lines
> On 02 Nov 2016, at 19:17, Jeff King <peff@peff.net> wrote:
> 
> This avoids us fooling around with $SHELL_PATH and the
> executable bit ourselves.
> 
> Signed-off-by: Jeff King <peff@peff.net>
> ---
> t/t0021-conversion.sh | 4 +---
> 1 file changed, 1 insertion(+), 3 deletions(-)
> 
> diff --git a/t/t0021-conversion.sh b/t/t0021-conversion.sh
> index a20b9f58e..dfde22549 100755
> --- a/t/t0021-conversion.sh
> +++ b/t/t0021-conversion.sh
> @@ -6,13 +6,11 @@ test_description='blob conversion via gitattributes'
> 
> TEST_ROOT="$(pwd)"
> 
> -cat <<EOF >"$TEST_ROOT/rot13.sh"
> -#!$SHELL_PATH
> +write_script <<\EOF "$TEST_ROOT/rot13.sh"
> tr \
>   'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' \
>   'nopqrstuvwxyzabcdefghijklmNOPQRSTUVWXYZABCDEFGHIJKLM'
> EOF
> -chmod +x "$TEST_ROOT/rot13.sh"
> 
> generate_random_characters () {
> 	LEN=$1
> -- 
> 2.11.0.rc0.258.gf434c15
> 

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?
Thanks,
Lars
 
Previous: Jeff KingNext: Jeff King
Message 10 of 30 in “What's cooking in git.git (Oct 2016, #09; Mon, 31)”
  1. Junio C HamanoOct 31, 2016
  2. Torsten BögershausenNov 2, 2016
  3. Junio C HamanoNov 2, 2016
  4. Johannes SchindelinNov 2, 2016
  5. Junio C HamanoNov 2, 2016
  6. Torsten BögershausenNov 2, 2016
  7. Jeff KingNov 2, 2016
  8. 0/4 t0021 perl portability fixupsJeff King, Nov 2, 2016
  9. 1/4 t0021: use write_script to create rot13 shell scriptJeff King, Nov 2, 2016
  10. Lars SchneiderNov 6, 2016
  11. Jeff KingNov 6, 2016
  12. Lars SchneiderNov 6, 2016
  13. 2/4 t0021: put $TEST_ROOT in $PATHJeff King, Nov 2, 2016
  14. Johannes SixtNov 3, 2016
  15. Jeff KingNov 3, 2016
  16. Johannes SixtNov 3, 2016
  17. Lars SchneiderNov 6, 2016
  18. 3/4 t0021: use $PERL_PATH for rot13-filter.plJeff King, Nov 2, 2016
  19. Lars SchneiderNov 6, 2016
  20. Jeff KingNov 6, 2016
  21. 4/4 t0021: fix filehandle usage on older perlJeff King, Nov 2, 2016
  22. Torsten BögershausenNov 2, 2016
  23. Lars SchneiderNov 6, 2016
  24. Johannes SixtNov 2, 2016
  25. Lars SchneiderNov 3, 2016
  26. Lars SchneiderNov 2, 2016
  27. Torsten BögershausenNov 5, 2016
  28. Karthik NayakNov 8, 2016
  29. Torsten BögershausenNov 5, 2016
  30. Karthik NayakNov 8, 2016

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.