Skip to content

Commit 33da196

Browse files
committed
Improve version extraction in install-tools.sh
Replaces grep and sed with awk for extracting tool versions from the versions file, allowing for comments and blank lines between section headers and version keys. This makes the script more robust and reliable.
1 parent 881d415 commit 33da196

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

scripts/install-tools.sh

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,17 @@ get_version() {
1414

1515
if [ -z "$section" ]; then
1616
# Top-level tool like [mdbook]
17-
grep -A 1 "^\[$tool\]" "$VERSIONS_FILE" | grep "version" | sed 's/.*"\(.*\)".*/\1/'
17+
# Use awk to handle comments/blank lines between section header and version key
18+
awk -v tool="$tool" '
19+
BEGIN { in_section = 0 }
20+
$0 ~ ("^\\[" tool "\\]$") { in_section = 1; next }
21+
in_section && /^\[/ { exit }
22+
in_section && /^version[[:space:]]*=/ {
23+
match($0, /"([^"]+)"/, arr)
24+
print arr[1]
25+
exit
26+
}
27+
' "$VERSIONS_FILE"
1828
else
1929
# Plugin in a section like [mdbook-plugins]
2030
awk -v section="$section" -v tool="$tool" '

0 commit comments

Comments
 (0)