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

[PATCH 14/15] git-am.sh: replace using expr for arithmetic operations with the equivalent shell builtin

From
Elia Pinto <gitter.spiros@gmail.com>
Date
Feb 4, 2016, 10:20 UTC
Message-ID
<1454581259-57095-1-git-send-email-gitter.spiros@gmail.com>

expr is considered generally antiquated. It is best to use for arithmetic operations the shell $((..)).

To quote POSIX:

"The expr utility has a rather difficult syntax [...] In many cases, the arithmetic and string features provided as part of the shell command language are easier to use than their equivalents in expr. Newly written scripts should avoid expr in favor of the new features within the shell."

Signed-off-by: Elia Pinto <gitter.spiros@gmail.com>
---
 git-am.sh | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/git-am.sh b/git-am.sh
index ee61a77..4f8148e 100755
--- a/git-am.sh
+++ b/git-am.sh
@@ -298,7 +298,7 @@ split_patches () {
 		this=0
 		for stgit in "$@"
 		do
-			this=$(expr "$this" + 1)
+			this=$(( "$this" + 1 ))
 			msgnum=$(printf "%0${prec}d" $this)
 			# Perl version of StGIT parse_patch. The first nonemptyline
 			# not starting with Author, From or Date is the
@@ -656,14 +656,14 @@ last=$(cat "$dotest/last")
 this=$(cat "$dotest/next")
 if test "$skip" = t
 then
-	this=$(expr "$this" + 1)
+	this=$(( "$this" + 1 ))
 	resume=
 fi
 
 while test "$this" -le "$last"
 do
 	msgnum=$(printf "%0${prec}d" $this)
-	next=$(expr "$this" + 1)
+	next=$(( "$this" + 1 ))
 	test -f "$dotest/$msgnum" || {
 		resume=
 		go_next
-- 
2.5.0
Next: Elia Pinto
Message 1 of 9 in “git-am.sh: replace using expr for arithmetic operations with the equivalent shell builtin”
  1. 14/15 git-am.sh: replace using expr for arithmetic operations with the equivalent shell builtinElia Pinto, Feb 4, 2016
  2. 15/15 t4032-diff-inter-hunk-context.sh: replace using expr for arithmetic operations with the equivalent shell builtinElia Pinto, Feb 4, 2016
  3. Johannes SchindelinFeb 4, 2016
  4. Elia PintoFeb 4, 2016
  5. Johannes SchindelinFeb 4, 2016
  6. Junio C HamanoFeb 4, 2016
  7. Eric SunshineFeb 4, 2016
  8. Elia PintoFeb 5, 2016
  9. Stefan BellerFeb 4, 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.