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

Re: [PATCH v3 2/2] mergetools: Simplify how we handle "vim" and "defaults"

From
Junio C Hamano <gitster@pobox.com>
Date
Jan 27, 2013, 04:25 UTC
Message-ID
<7vd2wrz1z1.fsf@alter.siamese.dyndns.org>
In-Reply-To
<CAJDDKr7E1NkMV0_G+6oY9O3iCS9OCEzR1HYssKpwh77swDUcig@mail.gmail.com>
David Aguilar <davvid@gmail.com> writes:
> I have a question. John mentioned that we can replace the use of
> "$(..)" with $(..) in shell.

I think it isn't so much about $(...) but more about quoting the RHS of assignment.

Consider these:
	var="$another_var"
	var="$(command)"
	var="$one_var$two_var"
	var="$another_var$(command)"

all of which _can_ be done without dq around the RHS, because the result of variable substitution and command substitution will not be subject to further word splitting.

I however find it easier to read with dq around the latter two, i.e. substitution and then concatenation of the result of substitution. The extra dq makes the intent of the author clearer, especially while reviewing a script written by other people whose understanding of the syntax I am not sure about ;-). Between var=$another and var="$another", the latter is slightly preferrable for the same reason.

One questionable case is:
	var=$(command "with quoted parameter")

It makes it a bit harder to scan if there is an extra set of dq around RHS, i.e.

	var="$(command "with quoted parameter")"

That case is easier to read without dq around it, or you could cheat by doing this:

	var="$(command 'with quoted parameter')"

In any case, as long as the result is correct, I do not have very strong preference either way.

Previous: David Aguilar
Message 4 of 4 in “mergetools: Simplify how we handle "vim" and "defaults"”
  1. 2/2 mergetools: Simplify how we handle "vim" and "defaults"David Aguilar, Jan 27, 2013
  2. Junio C HamanoJan 27, 2013
  3. David AguilarJan 27, 2013
  4. Junio C HamanoJan 27, 2013

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.