Skip to content

fix(expansion): ${@/#/prefix} and ${@/%/suffix} do not apply to positional params #1160

@chaliy

Description

@chaliy

Summary

Pattern substitution on `$@` (all positional parameters) with `#` (prefix) or `%` (suffix) anchors does not modify the values.

Reproduction

set -- "hello" "world" "test"
prefix="tag_"
set -- "${@/#/$prefix}"
echo "$@"
# Expected: tag_hello tag_world tag_test
# Actual: hello world test (unchanged)

set -- "hello" "world"
set -- "${@/%/.html}"
echo "$@"
# Expected: hello.html world.html
# Actual: hello world (unchanged)

Real bash comparison

$ bash -c 'set -- "hello" "world"; p="tag_"; set -- "${@/#/$p}"; echo "$@"'
tag_hello tag_world

Context

Bashblog uses this in `posts_with_tags()` to construct tag file paths from tag names:

posts_with_tags() {
    (($# < 1)) && return
    set -- "${@/#/$prefix_tags}"   # prepend "tag_" to each arg
    set -- "${@/%/.html}"          # append ".html" to each arg
    sed -n '...' "$@"
}

Without this, the function passes raw tag names as filenames instead of `tag_NAME.html`, breaking tag page lookups.

Expected behavior

`${@/#/string}` should prepend `string` to each positional parameter. `${@/%/string}` should append `string` to each positional parameter. Same for `${array[@]/#/}` and `${array[@]/%/}`.

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