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

[PATCH v2 002/142] git-am.sh: use the $( ... ) construct for command substitution

From
Elia Pinto <gitter.spiros@gmail.com>
Date
Mar 25, 2014, 17:22 UTC
Message-ID
<1395768283-31135-3-git-send-email-gitter.spiros@gmail.com>
In-Reply-To
<1395768283-31135-1-git-send-email-gitter.spiros@gmail.com>

The Git CodingGuidelines prefer the $( ... ) construct for command substitution instead of using the back-quotes, or grave accents (`..`).

The backquoted form is the historical method for command substitution, and is supported by POSIX. However, all but the simplest uses become complicated quickly. In particular, embedded command substitutions and/or the use of double quotes require careful escaping with the backslash character. Because of this the POSIX shell adopted the $(…) feature from the Korn shell.

The patch was generated by the simple script
for _f in $(find . -name "*.sh")
do
  sed -i 's@`\(.*\)`@$(\1)@g' ${_f}
done
Signed-off-by: Elia Pinto <gitter.spiros@gmail.com>
---
 git-am.sh |   30 +++++++++++++++---------------
 1 file changed, 15 insertions(+), 15 deletions(-)
diff --git a/git-am.sh b/git-am.sh
index 78517f2..1b638e8 100755
--- a/git-am.sh
+++ b/git-am.sh
@@ -125,7 +125,7 @@ cannot_fallback () {
 }
 
 fall_back_3way () {
-    O_OBJECT=`cd "$GIT_OBJECT_DIRECTORY" && pwd`
+    O_OBJECT=$(cd "$GIT_OBJECT_DIRECTORY" && pwd)
 
     rm -fr "$dotest"/patch-merge-*
     mkdir "$dotest/patch-merge-tmp-dir"
@@ -275,7 +275,7 @@ split_patches () {
 		then
 			clean_abort "$(gettext "Only one StGIT patch series can be applied at once")"
 		fi
-		series_dir=`dirname "$1"`
+		series_dir=$(dirname "$1")
 		series_file="$1"
 		shift
 		{
@@ -298,8 +298,8 @@ split_patches () {
 		this=0
 		for stgit in "$@"
 		do
-			this=`expr "$this" + 1`
-			msgnum=`printf "%0${prec}d" $this`
+			this=$(expr "$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
 			# subject, and the body starts with the next nonempty
@@ -644,26 +644,26 @@ fi
 git_apply_opt=$(cat "$dotest/apply-opt")
 if test "$(cat "$dotest/sign")" = t
 then
-	SIGNOFF=`git var GIT_COMMITTER_IDENT | sed -e '
+	SIGNOFF=$(git var GIT_COMMITTER_IDENT | sed -e '
 			s/>.*/>/
 			s/^/Signed-off-by: /'
-		`
+		)
 else
 	SIGNOFF=
 fi
 
-last=`cat "$dotest/last"`
-this=`cat "$dotest/next"`
+last=$(cat "$dotest/last")
+this=$(cat "$dotest/next")
 if test "$skip" = t
 then
-	this=`expr "$this" + 1`
+	this=$(expr "$this" + 1)
 	resume=
 fi
 
 while test "$this" -le "$last"
 do
-	msgnum=`printf "%0${prec}d" $this`
-	next=`expr "$this" + 1`
+	msgnum=$(printf "%0${prec}d" $this)
+	next=$(expr "$this" + 1)
 	test -f "$dotest/$msgnum" || {
 		resume=
 		go_next
@@ -739,16 +739,16 @@ To restore the original branch and stop patching run \"\$cmdline --abort\"."
 	'')
 	    if test '' != "$SIGNOFF"
 	    then
-		LAST_SIGNED_OFF_BY=`
+		LAST_SIGNED_OFF_BY=$(
 		    sed -ne '/^Signed-off-by: /p' \
 		    "$dotest/msg-clean" |
 		    sed -ne '$p'
-		`
-		ADD_SIGNOFF=`
+		)
+		ADD_SIGNOFF=$(
 		    test "$LAST_SIGNED_OFF_BY" = "$SIGNOFF" || {
 		    test '' = "$LAST_SIGNED_OFF_BY" && echo
 		    echo "$SIGNOFF"
-		}`
+		})
 	    else
 		ADD_SIGNOFF=
 	    fi
-- 
1.7.10.4
Previous: Matthieu MoyNext: Elia Pinto
Message 9 of 101 in “Use the $( ... ) construct for command substitution instead of using the back-quotes”
  1. 000/142 Use the $( ... ) construct for command substitution instead of using the back-quotesElia Pinto, Mar 25, 2014
  2. 001/142 check-builtins.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  3. Junio C HamanoMar 25, 2014
  4. David KastrupMar 25, 2014
  5. Matthieu MoyMar 26, 2014
  6. Junio C HamanoMar 25, 2014
  7. Junio C HamanoMar 25, 2014
  8. Matthieu MoyMar 26, 2014
  9. 002/142 git-am.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  10. 003/142 git-pull.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  11. 004/142 git-rebase--merge.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  12. 005/142 git-rebase.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  13. 006/142 git-stash.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  14. 007/142 git-web--browse.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  15. 008/142 unimplemented.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  16. 009/142 t0001-init.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  17. Junio C HamanoMar 25, 2014
  18. 010/142 t0010-racy-git.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  19. 011/142 t0020-crlf.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  20. 012/142 t0025-crlf-auto.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  21. 013/142 t0026-eol-config.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  22. 014/142 t0030-stripspace.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  23. 015/142 t0300-credentials.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  24. 016/142 t1000-read-tree-m-3way.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  25. 017/142 t1001-read-tree-m-2way.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  26. 018/142 t1002-read-tree-m-u-2way.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  27. 019/142 t1003-read-tree-prefix.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  28. 020/142 t1004-read-tree-m-u-wf.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  29. 021/142 t1020-subdirectory.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  30. 022/142 t1050-large.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  31. 023/142 t1100-commit-tree-options.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  32. 024/142 t1401-symbolic-ref.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  33. 025/142 t1410-reflog.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  34. 026/142 t1511-rev-parse-caret.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  35. 027/142 t1512-rev-parse-disambiguation.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  36. 028/142 t2102-update-index-symlinks.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  37. 029/142 t3030-merge-recursive.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  38. 030/142 t3100-ls-tree-restrict.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  39. 031/142 t3101-ls-tree-dirname.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  40. 032/142 t3210-pack-refs.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  41. 033/142 t3403-rebase-skip.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  42. 034/142 t3511-cherry-pick-x.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  43. 035/142 t3600-rm.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  44. 036/142 t3700-add.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  45. 037/142 t3905-stash-include-untracked.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  46. 038/142 t3910-mac-os-precompose.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  47. 039/142 t4006-diff-mode.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  48. 040/142 t4010-diff-pathspec.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  49. 041/142 t4012-diff-binary.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  50. 042/142 t4013-diff-various.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  51. 043/142 t4014-format-patch.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  52. 044/142 t4036-format-patch-signer-mime.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  53. 045/142 t4038-diff-combined.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  54. 046/142 t4057-diff-combined-paths.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  55. 047/142 t4116-apply-reverse.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  56. 048/142 t4119-apply-config.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  57. 049/142 t4204-patch-id.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  58. 050/142 t5000-tar-tree.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  59. 051/142 t5003-archive-zip.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  60. 052/142 t5100-mailinfo.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  61. 053/142 t5300-pack-object.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  62. 054/142 t5301-sliding-window.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  63. 055/142 t5302-pack-index.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  64. 056/142 t5303-pack-corruption-resilience.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  65. 057/142 t5304-prune.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  66. 058/142 t5305-include-tag.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  67. 059/142 t5500-fetch-pack.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  68. 060/142 t5505-remote.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  69. 061/142 t5506-remote-groups.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  70. 062/142 t5510-fetch.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  71. 063/142 t5515-fetch-merge-logic.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  72. 064/142 t5516-fetch-push.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  73. 065/142 t5517-push-mirror.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  74. 066/142 t5520-pull.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  75. 067/142 t5522-pull-symlink.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  76. 068/142 t5530-upload-pack-error.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  77. 069/142 t5537-fetch-shallow.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  78. 070/142 t5538-push-shallow.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  79. 071/142 t5550-http-fetch-dumb.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  80. 072/142 t5551-http-fetch-smart.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  81. 073/142 t5570-git-daemon.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  82. 074/142 t5601-clone.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  83. 075/142 t5700-clone-reference.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  84. 076/142 t5710-info-alternate.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  85. 077/142 t5900-repo-selection.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  86. 078/142 t6001-rev-list-graft.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  87. 079/142 t6002-rev-list-bisect.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  88. 080/142 t6015-rev-list-show-all-parents.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  89. 081/142 t6032-merge-large-rename.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  90. 082/142 t6034-merge-rename-nocruft.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  91. 083/142 t6132-pathspec-exclude.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  92. 084/142 t7001-mv.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  93. 085/142 t7003-filter-branch.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  94. 086/142 t7004-tag.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  95. 087/142 t7006-pager.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  96. 088/142 t7103-reset-bare.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  97. 089/142 t7406-submodule-update.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  98. Junio C HamanoMar 25, 2014
  99. Matthieu MoyMar 26, 2014
  100. Eric SunshineMar 26, 2014
  101. Elia PintoMar 26, 2014

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.