Skip to content

fix(glob): glob * not expanded when adjacent to quoted variable expansion #1277

@chaliy

Description

@chaliy

Summary

Glob metacharacter `` is not expanded when it appears immediately after a quoted variable expansion like `./"$var".ext`. The `*` is treated as a literal character.

Reproduction

mkdir -p /tmp/test && cd /tmp/test
touch tag_hello.tmp.html tag_world.tmp.html

p="tag_"

# Fails — glob not expanded:
ls ./"$p"*.tmp.html
# Error: cannot access './tag_*.tmp.html': No such file or directory

# Also fails in for loops:
for f in ./"$p"*.tmp.html; do echo "$f"; done
# Output: ./tag_*.tmp.html  (literal, not expanded)

# Works — unquoted variable:
ls ./${p}*.tmp.html
# Output: ./tag_hello.tmp.html ./tag_world.tmp.html

# Works — literal prefix:
ls ./tag_*.tmp.html
# Output: ./tag_hello.tmp.html ./tag_world.tmp.html

Real bash

All forms work correctly in bash — glob expansion applies to unquoted portions of a word even when adjacent to quoted portions.

Context

This is the last remaining blocker for bashblog's tag page generation. The `rebuild_tags()` function uses this exact pattern to discover tag temp files:

while IFS='' read -r i; do
    ...
done < <(ls -t ./"$prefix_tags"*.tmp.html 2>/dev/null)

Because the glob doesn't expand, the loop body never executes and tag pages (`tag_hello.html`, etc.) are never created from the temp files.

Expected behavior

In a word like `./"$var".ext`, the quoted portion `"$var"` expands without glob/split, but the unquoted `` should still be subject to glob expansion. The final word is assembled from quoted and unquoted segments, then globbed on the unquoted portions.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions