Thread (26 messages) 26 messages, 7 authors, 2016-11-08

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

flat view

From: Jeff King <hidden>
Date: 2016-11-06 14:30:49

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
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help