testmark-bash

examples: find the library from BASH_SOURCE rather than $0, which is right even when the file is sourced.

commit 55a0a7dedbf1c93caa99dca8d005befd2fa24af6 · parent c290ea86e2 · browse this tree
Ximianth, 2026-10-24 15:05:05 UTC

diff --git a/README.md b/README.md
index 43ae9b3..28a89af 100644
--- a/README.md
+++ b/README.md
@@ -113,7 +113,7 @@ A whole example
 #!/bin/bash
 ## Checks todos.sh against every case in todos.md.
 ## Run with TESTMARK_REGEN=1 to update todos.md to match what todos.sh does now; then review the change with `git diff`.
-source "$(dirname "$0")/../lib/testmark.bash"
+source "$(dirname "${BASH_SOURCE[0]}")/../lib/testmark.bash"
 
 exercise_todos() {
 	./todos.sh /dev/stdin
diff --git a/examples/test-todos.sh b/examples/test-todos.sh
index 51f1d0c..13ef873 100755
--- a/examples/test-todos.sh
+++ b/examples/test-todos.sh
@@ -1,7 +1,7 @@
 #!/bin/bash
 ## Checks todos.sh against every case in todos.md.
 ## Run with TESTMARK_REGEN=1 to update todos.md to match what todos.sh does now; then review the change with `git diff`.
-source "$(dirname "$0")/../lib/testmark.bash"
+source "$(dirname "${BASH_SOURCE[0]}")/../lib/testmark.bash"
 
 exercise_todos() {
 	./todos.sh /dev/stdin