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

[PATCH 056/144] t5302-pack-index.sh: use the $( ... ) construct for command substitution

From
Elia Pinto <gitter.spiros@gmail.com>
Date
Mar 25, 2014, 08:25 UTC
Message-ID
<1395735989-3396-57-git-send-email-gitter.spiros@gmail.com>
In-Reply-To
<1395735989-3396-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.

Signed-off-by: Elia Pinto <gitter.spiros@gmail.com>
---
 t/t5302-pack-index.sh |   34 +++++++++++++++++-----------------
 1 file changed, 17 insertions(+), 17 deletions(-)
diff --git a/t/t5302-pack-index.sh b/t/t5302-pack-index.sh
index 4bbb718..442ee5c 100755
--- a/t/t5302-pack-index.sh
+++ b/t/t5302-pack-index.sh
@@ -14,21 +14,21 @@ test_expect_success \
      i=1 &&
      while test $i -le 100
      do
-         iii=`printf '%03i' $i`
+         iii=$(printf '%03i' $i)
          test-genrandom "bar" 200 > wide_delta_$iii &&
          test-genrandom "baz $iii" 50 >> wide_delta_$iii &&
          test-genrandom "foo"$i 100 > deep_delta_$iii &&
-         test-genrandom "foo"`expr $i + 1` 100 >> deep_delta_$iii &&
-         test-genrandom "foo"`expr $i + 2` 100 >> deep_delta_$iii &&
+         test-genrandom "foo"$(expr $i + 1) 100 >> deep_delta_$iii &&
+         test-genrandom "foo"$(expr $i + 2) 100 >> deep_delta_$iii &&
          echo $iii >file_$iii &&
          test-genrandom "$iii" 8192 >>file_$iii &&
          git update-index --add file_$iii deep_delta_$iii wide_delta_$iii &&
-         i=`expr $i + 1` || return 1
+         i=$(expr $i + 1) || return 1
      done &&
      { echo 101 && test-genrandom 100 8192; } >file_101 &&
      git update-index --add file_101 &&
-     tree=`git write-tree` &&
-     commit=`git commit-tree $tree </dev/null` && {
+     tree=$(git write-tree) &&
+     commit=$(git commit-tree $tree </dev/null) && {
 	 echo $tree &&
 	 git ls-tree $tree | sed -e "s/.* \\([0-9a-f]*\\)	.*/\\1/"
      } >obj-list &&
@@ -152,10 +152,10 @@ test_expect_success \
     '[index v1] 2) create a stealth corruption in a delta base reference' \
     '# This test assumes file_101 is a delta smaller than 16 bytes.
      # It should be against file_100 but we substitute its base for file_099
-     sha1_101=`git hash-object file_101` &&
-     sha1_099=`git hash-object file_099` &&
-     offs_101=`index_obj_offset 1.idx $sha1_101` &&
-     nr_099=`index_obj_nr 1.idx $sha1_099` &&
+     sha1_101=$(git hash-object file_101) &&
+     sha1_099=$(git hash-object file_099) &&
+     offs_101=$(index_obj_offset 1.idx $sha1_101) &&
+     nr_099=$(index_obj_nr 1.idx $sha1_099) &&
      chmod +w ".git/objects/pack/pack-${pack1}.pack" &&
      dd of=".git/objects/pack/pack-${pack1}.pack" seek=$(($offs_101 + 1)) \
         if=".git/objects/pack/pack-${pack1}.idx" \
@@ -193,10 +193,10 @@ test_expect_success \
     '[index v2] 2) create a stealth corruption in a delta base reference' \
     '# This test assumes file_101 is a delta smaller than 16 bytes.
      # It should be against file_100 but we substitute its base for file_099
-     sha1_101=`git hash-object file_101` &&
-     sha1_099=`git hash-object file_099` &&
-     offs_101=`index_obj_offset 1.idx $sha1_101` &&
-     nr_099=`index_obj_nr 1.idx $sha1_099` &&
+     sha1_101=$(git hash-object file_101) &&
+     sha1_099=$(git hash-object file_099) &&
+     offs_101=$(index_obj_offset 1.idx $sha1_101) &&
+     nr_099=$(index_obj_nr 1.idx $sha1_099) &&
      chmod +w ".git/objects/pack/pack-${pack1}.pack" &&
      dd of=".git/objects/pack/pack-${pack1}.pack" seek=$(($offs_101 + 1)) \
         if=".git/objects/pack/pack-${pack1}.idx" \
@@ -222,11 +222,11 @@ test_expect_success \
     'rm -f .git/objects/pack/* &&
      git index-pack --index-version=2 --stdin < "test-1-${pack1}.pack" &&
      git verify-pack ".git/objects/pack/pack-${pack1}.pack" &&
-     obj=`git hash-object file_001` &&
-     nr=`index_obj_nr ".git/objects/pack/pack-${pack1}.idx" $obj` &&
+     obj=$(git hash-object file_001) &&
+     nr=$(index_obj_nr ".git/objects/pack/pack-${pack1}.idx" $obj) &&
      chmod +w ".git/objects/pack/pack-${pack1}.idx" &&
      printf xxxx | dd of=".git/objects/pack/pack-${pack1}.idx" conv=notrunc \
-        bs=1 count=4 seek=$((8 + 256 * 4 + `wc -l <obj-list` * 20 + $nr * 4)) &&
+        bs=1 count=4 seek=$((8 + 256 * 4 + $(wc -l <obj-list) * 20 + $nr * 4)) &&
      ( while read obj
        do git cat-file -p $obj >/dev/null || exit 1
        done <obj-list ) &&
-- 
1.7.10.4
Previous: Elia PintoNext: Elia Pinto
Message 61 of 113 in “Use the $( ... ) construct for command substitution instead of using the back-quotes”
  1. 000/144 Use the $( ... ) construct for command substitution instead of using the back-quotesElia Pinto, Mar 25, 2014
  2. 001/144 check-builtins.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  3. Matthieu MoyMar 25, 2014
  4. Elia PintoMar 25, 2014
  5. 002/144 git-am.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  6. 003/144 git-pull.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  7. 004/144 git-rebase--merge.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  8. 005/144 git-rebase.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  9. 006/144 git-stash.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  10. 007/144 git-web--browse.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  11. 008/144 unimplemented.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  12. 009/144 t0001-init.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  13. 010/144 t0010-racy-git.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  14. 011/144 t0020-crlf.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  15. 012/144 t0025-crlf-auto.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  16. 013/144 t0026-eol-config.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  17. 014/144 t0030-stripspace.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  18. 015/144 t0204-gettext-reencode-sanity.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  19. Matthieu MoyMar 25, 2014
  20. Elia PintoMar 25, 2014
  21. 016/144 t0300-credentials.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  22. 017/144 t1000-read-tree-m-3way.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  23. 018/144 t1001-read-tree-m-2way.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  24. 019/144 t1002-read-tree-m-u-2way.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  25. 020/144 t1003-read-tree-prefix.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  26. 021/144 t1004-read-tree-m-u-wf.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  27. 022/144 t1020-subdirectory.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  28. 023/144 t1050-large.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  29. 024/144 t1100-commit-tree-options.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  30. 025/144 t1401-symbolic-ref.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  31. 026/144 t1410-reflog.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  32. 027/144 t1511-rev-parse-caret.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  33. 028/144 t1512-rev-parse-disambiguation.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  34. 029/144 t2102-update-index-symlinks.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  35. 030/144 t3030-merge-recursive.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  36. 031/144 t3100-ls-tree-restrict.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  37. 032/144 t3101-ls-tree-dirname.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  38. 033/144 t3210-pack-refs.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  39. 034/144 t3403-rebase-skip.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  40. 035/144 t3511-cherry-pick-x.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  41. 036/144 t3600-rm.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  42. 037/144 t3700-add.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  43. 038/144 t3905-stash-include-untracked.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  44. 039/144 t3910-mac-os-precompose.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  45. 040/144 t4006-diff-mode.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  46. 041/144 t4010-diff-pathspec.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  47. 042/144 t4012-diff-binary.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  48. 043/144 t4013-diff-various.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  49. 044/144 t4014-format-patch.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  50. 045/144 t4036-format-patch-signer-mime.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  51. 046/144 t4038-diff-combined.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  52. 047/144 t4057-diff-combined-paths.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  53. 048/144 t4116-apply-reverse.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  54. 049/144 t4119-apply-config.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  55. 050/144 t4204-patch-id.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  56. 051/144 t5000-tar-tree.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  57. 052/144 t5003-archive-zip.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  58. 053/144 t5100-mailinfo.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  59. 054/144 t5300-pack-object.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  60. 055/144 t5301-sliding-window.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  61. 056/144 t5302-pack-index.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  62. 057/144 t5303-pack-corruption-resilience.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  63. 058/144 t5304-prune.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  64. 059/144 t5305-include-tag.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  65. 060/144 t5500-fetch-pack.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  66. 061/144 t5505-remote.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  67. 062/144 t5506-remote-groups.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  68. 063/144 t5510-fetch.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  69. 064/144 t5515-fetch-merge-logic.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  70. 065/144 t5516-fetch-push.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  71. 066/144 t5517-push-mirror.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  72. 067/144 t5520-pull.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  73. 068/144 t5522-pull-symlink.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  74. 069/144 t5530-upload-pack-error.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  75. 070/144 t5537-fetch-shallow.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  76. 071/144 t5538-push-shallow.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  77. 072/144 t5550-http-fetch-dumb.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  78. 073/144 t5551-http-fetch-smart.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  79. 074/144 t5570-git-daemon.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  80. 075/144 t5601-clone.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  81. 076/144 t5700-clone-reference.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  82. 077/144 t5710-info-alternate.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  83. 078/144 t5900-repo-selection.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  84. 079/144 t6001-rev-list-graft.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  85. 080/144 t6002-rev-list-bisect.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  86. 081/144 t6015-rev-list-show-all-parents.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  87. 082/144 t6032-merge-large-rename.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  88. 083/144 t6034-merge-rename-nocruft.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  89. 084/144 t6111-rev-list-treesame.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  90. Matthieu MoyMar 25, 2014
  91. Elia PintoMar 25, 2014
  92. 085/144 t6132-pathspec-exclude.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  93. 086/144 t7001-mv.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  94. 087/144 t7003-filter-branch.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  95. 088/144 t7004-tag.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  96. 089/144 t7006-pager.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  97. 090/144 t7103-reset-bare.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  98. 091/144 t7406-submodule-update.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  99. 092/144 t7408-submodule-reference.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  100. 093/144 t7504-commit-msg-hook.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  101. 094/144 t7505-prepare-commit-msg-hook.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  102. 095/144 t7602-merge-octopus-many.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  103. 096/144 t7700-repack.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  104. 097/144 t8003-blame-corner-cases.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  105. 098/144 t9001-send-email.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  106. 099/144 t9101-git-svn-props.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  107. Eric WongMar 29, 2014
  108. 100/144 t9104-git-svn-follow-parent.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  109. 101/144 t9105-git-svn-commit-diff.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  110. 102/144 t9107-git-svn-migrate.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  111. 103/144 t9108-git-svn-glob.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  112. 104/144 t9109-git-svn-multi-glob.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 2014
  113. 105/144 t9110-git-svn-use-svm-props.sh: use the $( ... ) construct for command substitutionElia Pinto, Mar 25, 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.