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[@]/%/}`.
Summary
Pattern substitution on `$@` (all positional parameters) with `#` (prefix) or `%` (suffix) anchors does not modify the values.
Reproduction
Real bash comparison
$ bash -c 'set -- "hello" "world"; p="tag_"; set -- "${@/#/$p}"; echo "$@"' tag_hello tag_worldContext
Bashblog uses this in `posts_with_tags()` to construct tag file paths from tag names:
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[@]/%/}`.