Re: [PATCH 1/4] t0021: use write_script to create rot13 shell script
> On 06 Nov 2016, at 15:29, Jeff King 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
Re: [PATCH 1/4] t0021: use write_script to create rot13 shell script
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). I don't think we really care about the distinction here, and either is fine (you would not ever pass an empty argument). So in this context you may pass in the interpreter: write_script "$PERL_PATH" <<\EOF ... some perl code ... EOF or it defaults to shell, which is what most of the callers want: write_script <<\EOF ... some shell code ... EOF -Peff
Re: [PATCH 1/4] t0021: use write_script to create rot13 shell script
> On 02 Nov 2016, at 19:17, Jeff King wrote: > > This avoids us fooling around with $SHELL_PATH and the > executable bit ourselves. > > Signed-off-by: Jeff King > --- > 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 <"$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
[PATCH 1/4] t0021: use write_script to create rot13 shell script
This avoids us fooling around with $SHELL_PATH and the executable bit ourselves. Signed-off-by: Jeff King --- 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 <"$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