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

Re: [PATCH] Avoid unportable nested double- and backquotes in shell scripts.

From
Jonathan Nieder <jrnieder@gmail.com>
Date
Jan 8, 2011, 18:22 UTC
Message-ID
<20110108182201.GB29788@burratino>
In-Reply-To
<20110108164825.GC28898@burratino>
Jonathan Nieder wrote:
Show 10 quoted lines
> From a quick grep, it seems you are right:
> 
>  $ git grep -c -F -e '`' -- 't/*.sh' | cut -d: -f2 | sum
>  65126     1
>  $ git grep -c -F -e '$(' -- 't/*.sh' | cut -d: -f2 | sum
>  64807     1
>  $ git grep -c -F -e '`' -- '*.sh' | cut -d: -f2 | sum
>  13350     1
>  $ git grep -c -F -e '$(' -- '*.sh' | cut -d: -f2 | sum
>  07810     1

sum does something totally different than I expected. With [1] comes the more reasonable

 $ git grep -c -F -e '`' -- 't/*.sh' | cut -d: -f2 | addup
 485
 $ git grep -c -F -e '$(' -- 't/*.sh' | cut -d: -f2 | addup
 2620
 $ git grep -c -F -e '`' -- '*.sh' | cut -d: -f2 | addup
 594
 $ git grep -c -F -e '$(' -- '*.sh' | cut -d: -f2 | addup
 3133
So the code bloat and use of backticks are less dire than I feared.
[1] 
	addup () {
		sum=0
		while read term
		do
			: $((sum = $sum + $term))
		done
		echo $sum
	}
Previous: Jonathan NiederNext: Junio C Hamano
Message 5 of 6 in “Avoid unportable nested double- and backquotes in shell scripts.”
  1. Avoid unportable nested double- and backquotes in shell scripts.Ralf Wildenhues, Jan 8, 2011
  2. Jonathan NiederJan 8, 2011
  3. Ralf WildenhuesJan 8, 2011
  4. Jonathan NiederJan 8, 2011
  5. Jonathan NiederJan 8, 2011
  6. Junio C HamanoJan 10, 2011

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.